Jul
21
Written by:
Steve Gray
7/21/2009 8:44 AM
The task here is to pass a username and password to a web service. We want to pass it not as a property of the web service, but in the SOAP header.
First, define the web service call, and give a name to the SoapHeader so that we can refer to it later
<WebMethod(), SoapHeader("myHeaderMemberVariable")> _
Public Function UpdateGP(ByVal doc As String, ByVal db As String, _
ByVal userID As String) As String
'validate the username and password
validateUser(myHeaderMemberVariable.username, myHeaderMemberVariable.password)
Return ""
End Function
Next, look at the call from a Win Forms app that calls the web service
Private Sub btnUpdateClient_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btnUpdateClient.Click
Dim webService As localhost.GPConnect = New localhost.GPConnect
webService.MyHeaderValue = New localhost.MyHeader
webService.MyHeaderValue.username = "brstest"
webService.MyHeaderValue.password = "testpass"
webService.Url = mstrURL
Dim strDoc As String
Dim xDoc As New Xml.XmlDocument
xDoc.Load("C:\projects\EConnect\tester\xmlDocs\updateClient.xml")
strDoc = xDoc.InnerXml
Try
webService.UpdateClient(strDoc, "sgray")
MsgBox("done")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Note that we are assigning the 'username' and 'password' properties
Last, look back at the first piece of code and note how we get references to those properties.
As always, I welcome your comments!