WEBSERVICE中的SOAP安全認證

服務器端(包括設計器生成的代碼)
Imports System
Imports System.Web.Services
Imports System.Web.Services.Protocols

' _
_
Public Class soapservice
Inherits System.Web.Services.WebService
Public Class MySoapHeader
Inherits SoapHeader
Public username As String
Public password As String
End Class

#Region " Web 服務設計器生成的代碼 "

Public Sub New()
MyBase.New()

'該調用是 Web 服務設計器所必需的。
InitializeComponent()

'在 InitializeComponent() 調用之後添加您自己的初始化代碼

End Sub

'Web 服務設計器所必需的
Private components As System.ComponentModel.IContainer

'注意: 以下過程是 Web 服務設計器所必需的
'可以使用 Web 服務設計器修改此過程。
'不要使用代碼編輯器修改它。
Private Sub InitializeComponent()
components = New System.ComponentModel.Container
End Sub

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
'CODEGEN: 此過程是 Web 服務設計器所必需的
'不要使用代碼編輯器修改它。
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

#End Region

' Add a member variable of the type deriving from SoapHeader.
Public temp As New MySoapHeader

' Apply a SoapHeader attribute.
SoapHeader("temp")> _
Public Function HelloWorld() As String
If temp.username = "admin" Then
Return temp.username
Else : Return "user爲空"
End If
End Function
End Class

客戶端(不包括設計器)
Imports System.Web.Services.Protocols

Dim h As localhost.MySoapHeader
Dim myheader As localhost.MySoapHeader
Dim proxy As localhost.soapservice = New localhost.soapservice
h = New localhost.MySoapHeader
h.password = "1"
h.username = "admin"

proxy.MySoapHeaderValue = h
Dim results As String = proxy.HelloWorld

TextBox1.Text = results
TextBox2.Text = h.username

發佈了27 篇原創文章 · 獲贊 0 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章