forked from dotnet/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsource.vb
119 lines (101 loc) · 4.08 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
Imports System.Xml
Imports System.Collections
Imports System.ServiceModel
Imports System.Security.Cryptography.X509Certificates
Imports System.ServiceModel.Security
Imports System.Security.Permissions
Imports System.Net
Imports System.Net.Security
Imports System.Runtime.Serialization
Imports System.Xml.Schema
Public Class Test
Public Shared Sub Main()
Try
Dim t As New Test()
t.Run()
Catch exc As Exception
Console.WriteLine("Message: {0}", exc.Message)
Console.ReadLine()
Finally
Console.WriteLine(vbLf & " " & vbLf & " Done")
Console.ReadLine()
End Try
End Sub
Private Sub Run()
'<snippet1>
ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf ValidateServerCertificate)
'</snippet1>
End Sub
'<snippet2>
Public Shared Function ValidateServerCertificate(ByVal sender As Object, _
ByVal certificate As X509Certificate, _
ByVal chain As X509Chain, _
ByVal sslPolicyErrors As SslPolicyErrors) As Boolean
'</snippet2>
If sslPolicyErrors = sslPolicyErrors.None Then
Return True
End If
Console.WriteLine("Certificate error: {0}", sslPolicyErrors)
' Do not allow this client to communicate with unauthenticated servers.
Return False
End Function
Private Sub CreateServiceHost()
Dim myServiceHost As New ServiceHost(GetType(Calculator))
'<snippet3>
With myServiceHost.Credentials.ClientCertificate.Authentication
.CertificateValidationMode = X509CertificateValidationMode.PeerOrChainTrust
.RevocationMode = X509RevocationMode.Offline
End With
'</snippet3>
End Sub
Private Sub CreateClient()
Dim myClient As New CalculatorClient()
'<snippet4>
With myClient.ClientCredentials.ServiceCertificate.Authentication
.CertificateValidationMode = X509CertificateValidationMode.PeerOrChainTrust
.RevocationMode = X509RevocationMode.Offline
End With
'</snippet4>
End Sub
<ServiceContract()> _
Public Interface ICalculator
<OperationContract()> _
Function Add(ByVal a As Double, ByVal b As Double) As Double
End Interface
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
<System.Diagnostics.DebuggerStepThroughAttribute()> _
<System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")> _
Public Class CalculatorClient
Inherits System.ServiceModel.ClientBase(Of ICalculator)
Implements ICalculator
Public Sub New()
End Sub
Public Sub New(ByVal endpointConfigurationName As String)
MyBase.New(endpointConfigurationName)
End Sub
Public Sub New(ByVal endpointConfigurationName As String, _
ByVal remoteAddress As String)
MyBase.New(endpointConfigurationName, remoteAddress)
End Sub
Public Sub New(ByVal endpointConfigurationName As String, _
ByVal remoteAddress As System.ServiceModel.EndpointAddress)
MyBase.New(endpointConfigurationName, remoteAddress)
End Sub
Public Sub New(ByVal binding As System.ServiceModel.Channels.Binding, _
ByVal remoteAddress As System.ServiceModel.EndpointAddress)
MyBase.New(binding, remoteAddress)
End Sub
Public Function Add(ByVal n1 As Double, _
ByVal n2 As Double) _
As Double Implements ICalculator.Add
Return MyBase.Channel.Add(n1, n2)
End Function
End Class
End Class