⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.vb

📁 Microsoft Mobile Development Handbook的代码,有C#,VB,C++的
💻 VB
字号:
Imports System.Net
Imports System.Security.Cryptography.X509Certificates

Public Class Form1

    ' <summary>
    ' TODO: Change URL to address on your own server
    ' </summary>
    Private ReadOnly webServiceURL As String = "https://dev/SecureService/Service.asmx"

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        System.Diagnostics.Debug.Assert(False, "Have you installed the SecureService Web Service from the sample code, and changed the webServiceURL field in this class to the correct URL? When you have, comment out this Assert in Form1_Load.")
    End Sub


    Private Sub MenuItemExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemExit.Click
        Me.Close()
    End Sub

    Private Sub MenuItemCallWithCallback_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemCallWithCallback.Click
        System.Net.ServicePointManager.CertificatePolicy = New TrustAllCertificatePolicy()
        CallSecureWebService()
    End Sub

    Private Sub MenuItemCallNoCallback_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemCallNoCallback.Click
        System.Net.ServicePointManager.CertificatePolicy = Nothing
        CallSecureWebService()
    End Sub

    Private Sub CallSecureWebService()
        Cursor.Current = Cursors.WaitCursor
        Try
            Dim websvc As SecureWebService.Service = New SelfSignedSSLCert.SecureWebService.Service()
            websvc.Url = webServiceURL
            Dim response As String = websvc.HelloSecureWorld()
            label1.Text = response
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Exception")
        Finally
            Cursor.Current = Cursors.Default
        End Try
    End Sub

End Class

Public Class TrustAllCertificatePolicy
    Implements System.Net.ICertificatePolicy

    Public Sub New()
    End Sub

    Public Function CheckValidationResult1(ByVal srvPoint As System.Net.ServicePoint, ByVal certificate As System.Security.Cryptography.X509Certificates.X509Certificate, ByVal request As System.Net.WebRequest, ByVal certificateProblem As Integer) As Boolean Implements System.Net.ICertificatePolicy.CheckValidationResult
        ' TODO: return true to trust all server certificates
        Return True
        ' TODO: Alternatively, edit Company name and Host name in code below, and uncomment
        ' to only accept specific server certificates
        'int UnTrustedRoot = (int)(0x800B010D & 0x000FFFFF);  
        'int UnTrustedCA = (int)(0x800B0112 & 0x000FFFFF);
        'if (certificateProblem == UnTrustedRoot || certificateProblem == UnTrustedCA)
        '{
        '    if (certificate.GetIssuerName().Equals("MyCompany") && request.RequestUri.Host.Equals("MyServer"))
        '        return true;
        '}
        'return false;

    End Function
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -