Call simple web service via Soap Client

Posted on 2005-04-19
Last Modified: 2009-07-29
I am new Soap in VB 6.  I thought I'd be able to just figure it out as I normally do.  However this proved to be a slow process because I cannot find a help file that contains description of the SoapClient object methods, properties etc.  I am looking a code sample that calls a service passes a name (string) then returns "hello" & name - that simple.  I am also looking for the location of the Soap toolkit help file (I have soap toolkit installed) This is actually more important than the sample

Many thanks
Question by:gbzhhu
    LVL 1

    Accepted Solution

    LVL 12

    Author Comment

    Both didn't help

    First one
    I am already to create the soapclient object and successfully call MSSoapInit method.  I didn't know where to go from there.  How to call the SayHi method of my service and pass a string to it displaying the returned string.  The service is written in Java (J2EE).  When I tried soapclient.SayHi("MyName") I get an error saying

    No Deserializer found to deserialize a ':name' using encoding style ''.

    The second one is for Office VBA.  I need this from VB 6.  I only have Office 97 anyway which doesn't support all that stuff

    LVL 12

    Author Comment

    Ok, go it fixed

    This is the page that helped me

    And this is my code as it stands, so I hope it helps someone else someday.  Live long EE

    Option Explicit

    Private Const ENC = ""
    Private Const XSI = ""
    Private Const XSD = ""
    Private Const URL = "http://ourserver:9888/WS_Hello01/servlet/rpcrouter"
    Private Const URI = "uri:HiWebService"
    'Private Const URI = ""
    Private Const Method = "sayHello"

    Private Sub Command1_Click()
        'Instantiate your SOAP Connector, Serializer and Reader. The Connector will handle the HTTP Connection, the Serializer will help you build the SOAP Envelope and the Reader will help you to access the result.
        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. Note that the "SoapAction" data is not consequential on the server side so the contents can be anything at all - It is a good idea to set it to the URI and Method name for easier identification when you are debugging and reading the SOAP messages.
        Connector.Property("EndPointURL") = URL
        Call Connector.Connect
        Connector.Property("SoapAction") = URI & "#" & Method
        Call Connector.BeginMessage
        'Associate your Serializer with your 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 - the root element is always the Service URI and method.
        Serializer.StartElement Method, URI, , "method"
        'Write each method parameter out as a child to the root element.
        Serializer.StartElement "name"
        Serializer.SoapAttribute "type", , "xsd:string", "xsi"
        Serializer.WriteString "Hassan"
        'End the root element, the body and the envelope.
        'Ending the message causes it to be sent.
        'Load the result into the Reader.
        Reader.Load Connector.OutputStream
        'If no fault loading the Reader then you can go ahead and pull the result of the invocation out of the DOM (Document Object Model) contained in the reader. There are many ways to do this ranging from methods highly specialised to the task at hand (and thus quite efficient) to more general and reusable methods that are not so efficient (like the method you will see in the downloadable source).
        If Not Reader.Fault Is Nothing Then
          MsgBox Reader.FaultString.Text, vbExclamation
    MsgBox Reader.Dom.Text
        End If

    End Sub

    LVL 12

    Author Comment

    Aryaomni,  I'll accept your answer as you are the one who tried to help.  Thanks

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now