I have a VB.NET 2008 program that accesses a Siebel web service defined by a WSDL and using the SOAP protocol.
The Siebel web service requires that a header containing the username, password and session type be included with the service request, but the header is not defined in the WSDL.
So, when I test the WSDL using the soapUI utility, the request as defined by the WSDL looks like this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:lov="http://www.siebel.com/xml/LOVService" xmlns:lis="http://www.siebel.com/xml/ListQuery">
<soapenv:Header/>
<soapenv:Body>
<lov:EAILOVGetListOfValues_Input>
<lis:ListsQuery>
<lis:ListQuery>
<lis:Active>Y</lis:Active>
<lis:LanguageCode>ENU</lis:LanguageCode>
<lis:Type>CUT_ACCOUNT_TYPE</lis:Type>
</lis:ListQuery>
</lis:ListsQuery>
</lov:EAILOVGetListOfValues_Input>
</soapenv:Body>
</soapenv:Envelope>
But the above does not work because it contains an empty header that is missing user and session credentials. It only works if I manually replace <soapenv:Header/> with a header containing the username, password, and session type as follows:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:lov="http://www.siebel.com/xml/LOVService" xmlns:lis="http://www.siebel.com/xml/ListQuery">
<soapenv:Header>
<UsernameToken xmlns="http://siebel.com/webservices">TESTUSER</UsernameToken>
<PasswordText xmlns="http://siebel.com/webservices">TESTPASSWORD</PasswordText>
<SessionType xmlns="http://siebel.com/webservices">None</SessionType>
</soapenv:Header>
<soapenv:Body>
<lov:EAILOVGetListOfValues_Input>
<lis:ListsQuery>
<lis:ListQuery>
<lis:Active>Y</lis:Active>
<lis:LanguageCode>ENU</lis:LanguageCode>
<lis:Type>CUT_ACCOUNT_TYPE</lis:Type>
</lis:ListQuery>
</lis:ListsQuery>
</lov:EAILOVGetListOfValues_Input>
</soapenv:Body>
</soapenv:Envelope>
My problem is that I cannot sort out how to translate the above into VB.NET 2008 code.
I have no problem importing the WSDL into Visual Studio 2008, defining the service in VB code and referencing the web service methods. However, I cannot sort out how to define the web service in VB such that the updated header in included in the web service request instead of the empty header. Consequently all my service requests from VB fail.
I can define a class that inherits from the SoapHeader class...
Public Class MySoapHeader : Inherits System.Web.Services.Protocols.SoapHeader
Public Username As String
Public Password As String
Public SessionType As String
End Class
...but how do I include this header in the SOAP request made from VB?
The sample code I am using to test this is a simple form with a button and a list box.
Public Class Form1
Private Sub btnGetLOV_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetLOV.Click
Dim MyService As New wsLOV.EAILOVPortClient
Dim MyInput As New wsLOV.EAILOVGetListOfValues_Input
Dim MyParams(0) As wsLOV.ListQuery
Dim temp As New wsLOV.ListQuery
Dim MyResult As New wsLOV.EAILOVGetListOfValues_Output
temp.Active = "Y"
temp.Type = "CUT_ACCOUNT_TYPE"
temp.LanguageCode = "ENU"
MyParams(0) = temp
MyInput.ListsQuery = MyParams
Dim MyRequest As New wsLOV.EAILOVGetListOfValuesRequest(MyInput)
MyResult = MyService.EAILOVGetListOfValues(MyInput)
End Sub
End Class
The code fails on the last line of the subroutine with a message indicating that the request has not been authenticated (Error Code: 10944642 Error Message: Error: Inbound SOAP Message - Session Token is missing or invalid or has expired) which is the same error I get in soapUI when I leave off the header containing username, password, and session type.
I believe I need to add the header to the endpoint (per http://msdn.microsoft.com/en-us/library/ms731749.aspx and http://msdn.microsoft.com/en-us/library/system.servicemodel.configuration.serviceendpointelement.aspx) but I am not sure how to do this in VB.