views:

462

answers:

0

Hi

I'm really stuck on getting my SOAP messages to work. I've tried many approaches but they all have the same problem in common: they don't have a security header.

The security header needs to contain a username and password. In VB.Net this is done by:

userNameAssertion.UsernameTokenProvider = new
UsernameTokenProvider(username, password);

Policy policy = new Policy();
policy.Assertions.Add(userNameAssertion);
proxy.SetPolicy(policy);

Two routines which I am developing which don't work are at the end of this message. There is a third which uses the MS SOAP Toolkit 3, but this gives so many errors it doesn't seem worth using if it's not necessary. If it is, then the errors alternate on first run are "class not registered" but subsequently "no such interface supported". That error occurs on the line:

Set sc_partservice = New SoapClient30

Any help to get this working will be greatly appreciated!

Thanks

David

Dim ENC As String
Dim XSI As String
Dim XSD As String

Sub SOAPsuds()

'Define Envelope Constants
    ENC = "http://schemas.xmlsoap.org/soap/encoding/"         'Encoding
    XSI = "http://www.w3.org/1999/XMLSchema-instance"         'Schema Instance
    XSD = "http://www.w3.org/1999/XMLSchema"                  'Schema

'Define Envelope Variables
    URL = "omitted"                                                             'Web Service
    Uri = "omitted"
    Method = "omitted"                                                          'Web Method

'Instantiate things
    Dim Connector As SoapConnector30
    Dim Serializer As SoapSerializer30
    Dim Reader As SoapReader30
    Set Connector = New HttpConnector30
    Set Serializer = New SoapSerializer30
    Set Reader = New SoapReader30

'Prepare the Connector to talk to the SOAP Server
    Connector.Property("EndPointURL") = URL
    Call Connector.Connect
    Connector.Property("SoapAction") = Uri & "#" & Method
    Call Connector.BeginMessage

'Associate Serializer with Connector
    Serializer.Init Connector.InputStream

'Start the SOAP Envelope and specify the Encoding and XML-Schema
    Serializer.StartEnvelope , ENC
    Serializer.SoapNamespace "xsi", XSI
    Serializer.SoapNamespace "SOAP-ENC", ENC
    Serializer.SoapNamespace "xsd", XSD

'Start the body of the message
    Serializer.StartBody
    Serializer.StartElement Method, Uri, , "method"

'Write each method parameter out as a child to the root element
    Serializer.StartElement "Author"
    Serializer.SoapAttribute "type", , "xsd:string", "xsi"
    Serializer.WriteString "Wilde, Oscar"
    Serializer.EndElement

'End the root element, the body and the envelope
    Serializer.EndElement
    Serializer.EndBody
    Serializer.EndEnvelope

'Ending the message causes it to be sent
    Connector.EndMessage

'Load the result into the Reader
    Reader.Load Connector.OutputStream

'If ok then pull result out of DOM
    If Not Reader.Fault Is Nothing Then
      MsgBox Reader.FaultString.text, vbExclamation
    Else
      Set Result = Reader.Dom
      '//parse the DOM to extract the result set
    End If

End Sub

and

Dim oDoc As MSXML2.DOMDocument

Private Sub WSTest1()
    On Error GoTo ErrorHandler

'Define Services
    Dim PartService
    Set PartService = CreateObject("MSSOAP.SoapClient30")
    PartService.MSSoapInit URL                                'string substituted

    xmlSchema "C:\Documents and Settings\User\Desktop\SOAP XML VB\Schemas\Request\GetByIDRequest.xsd"

'Query Services
    test = (PartService.GetByID(oDoc.documentElement))

    Exit Sub

'Handle WSDL Errors
ErrorHandler:
    If Err.Number = -2147024809 Then
        MsgBox "run-time error: '" & Err.Number & "':" & Chr(13) & Chr(13) & Err.Description & Chr(13) & "This is a WSDL Error"
    End If

End Sub

Function xmlSchema(StrXML)

        Dim fSuccess As Boolean

        Set oDoc = New MSXML2.DOMDocument
        oDoc.async = False
        oDoc.validateOnParse = False
        fSuccess = oDoc.Load(StrXML)
        If Not fSuccess Then
          MsgBox oDoc.parseError.reason
        End If

End Function