forked from dotnet/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsource.vb
130 lines (102 loc) · 4.01 KB
/
source.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
Imports System.ServiceModel
Imports System.Security.Permissions
Imports System.Security.Cryptography.X509Certificates
Public Class Test
Public Shared Sub Main()
Try
Dim t As New Test()
't.TcpMessageWithCredentialWindows();
t.AllConfig()
Catch exc As System.Exception
Console.WriteLine(exc.Message)
Console.ReadLine()
End Try
End Sub
Private Sub AllConfig()
Dim sh As New ServiceHost(GetType(Calculator))
sh.Open()
Console.WriteLine("Listening")
Console.ReadLine()
End Sub
Private Sub MakeTransportBinding()
'<snippet5>
'<snippet1>
Dim b As New WSHttpBinding()
b.Security.Mode = SecurityMode.Transport
'</snippet1>
b.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows
'</snippet5>
End Sub
Private Sub MakeMessageBinding()
'<snippet6>
'<snippet2>
Dim b As New WSHttpBinding()
b.Security.Mode = SecurityMode.Message
'</snippet2>
b.Security.Message.ClientCredentialType = MessageCredentialType.Certificate
'</snippet6>
End Sub
Private Sub TransportWithMessageBinding()
'<snippet3>
Dim b As New WSHttpBinding()
b.Security.Mode = SecurityMode.TransportWithMessageCredential
'</snippet3>
End Sub
Private Sub SetModeViaConstructor()
'<snippet4>
Dim b As New WSHttpBinding(SecurityMode.Message)
'</snippet4>
End Sub
Private Sub HttpMessageWithCredential()
'<snippet7>
Dim b As New WSHttpBinding()
b.Security.Mode = SecurityMode.TransportWithMessageCredential
b.Security.Message.ClientCredentialType = MessageCredentialType.Certificate
' The SSL certificate is bound to port 8006 using the HttpCfg.exe tool.
Dim httpsAddress As New Uri("https://localMachineName:8006/base")
Dim sh As New ServiceHost(GetType(Calculator), httpsAddress)
sh.AddServiceEndpoint(GetType(ICalculator), b, "HttpsCalculator")
sh.Open()
Console.WriteLine("Listening")
Console.ReadLine()
'</snippet7>
End Sub
Private Sub TcpMessageWithCredential()
'<snippet8>
Dim b As New NetTcpBinding(SecurityMode.TransportWithMessageCredential)
b.Security.Message.ClientCredentialType = MessageCredentialType.Certificate
Dim netTcpAddress As New Uri("net.tcp://baseAddress")
Dim sh As New ServiceHost(GetType(Calculator), netTcpAddress)
sh.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindByIssuerName, "Contoso.com")
sh.AddServiceEndpoint(GetType(ICalculator), b, "TcpCalculator")
sh.Open()
Console.WriteLine("Listening")
Console.ReadLine()
'</snippet8>
End Sub
Private Sub TcpMessageWithCredentialWindows()
'<snippet9>
Dim b As New NetTcpBinding(SecurityMode.TransportWithMessageCredential)
b.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows
b.Security.Message.ClientCredentialType = MessageCredentialType.Certificate
Dim netTcpAddress As New Uri("net.tcp://Tcp")
Dim sh As New ServiceHost(GetType(Calculator), netTcpAddress)
sh.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindByIssuerName, "Contoso.com")
sh.AddServiceEndpoint(GetType(ICalculator), b, "TcpCalculator")
sh.Open()
Console.WriteLine("Listening")
Console.ReadLine()
'</snippet9>
End Sub
End Class
<ServiceContract()> _
Interface ICalculator
<OperationContract()> _
Function Add(ByVal a As Double, ByVal b As Double) As Double
End Interface 'ICalculator
Public Class Calculator
Implements ICalculator
Public Function Add(ByVal a As Double, ByVal b As Double) As Double Implements ICalculator.Add
Return a + b
End Function
End Class