customsoapheaderform.vb

来自「清华大学出版社出版的 移动应用开发宝典 张大威(2008)的附书源代码」· VB 代码 · 共 44 行

VB
44
字号
Imports CustomSOAPHeaders.CustomSoapHeadersService

Public Class CustomSOAPHeaderForm

    Private ReadOnly WebServiceURL As String = "http://myServer/BasicAuthService/Service.asmx"

    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
        invokeIt(Nothing)
    End Sub

    Private Sub button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button2.Click
        Dim hdr As AuthHeader = New AuthHeader()
        hdr.Username = "andy"
        hdr.Password = "WRONG"
        invokeIt(hdr)
    End Sub

    Private Sub button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button3.Click
        Dim hdr As AuthHeader = New AuthHeader()
        hdr.Username = "andy"
        hdr.Password = "P455w0rd"
        invokeIt(hdr)
    End Sub

    Private Sub invokeIt(ByVal hdr As AuthHeader)
        'Check that the Web Service URL is updated
        System.Diagnostics.Debug.Assert(Not Me.WebServiceURL.IndexOf("myServer") = -1, "You must change the value of the WebServiceURL field to the URL where you have installed the BasicAuthService Web Service")

        Dim ws As SOAPHeaderService = New SOAPHeaderService()
        ws.Url = Me.WebServiceURL

        ws.AuthHeaderValue = hdr
        Try
            Dim response As Boolean = ws.Authenticate()
            label1.Text = "Web Service returned: " + response.ToString()

        Catch ex As System.Web.Services.Protocols.SoapException
            label1.Text = "SOAP exception, message: " + ex.Message
        End Try
    End Sub


End Class

⌨️ 快捷键说明

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