Visual Basic 6 Client for Apache SOAP Using the Low Level API

The following instructions produce Visual Basic 6 client applications for the Apache SOAP stock quote and address book samples. They use the low level API from the Microsoft SOAP Toolkit. There are instructions elsewhere for using the high level API.

The instructions in this document assume that Apache SOAP is installed according to these instructions. It is also assumed that Visual Basic 6 is installed. The version I am running is SP5. My tests were run on NT Server 4 SP 6 and Windows 2000 Server SP1.

Install SOAP Toolkit
Run the Stock Quote client
Trace the Stock Quote client
Run the Address Book client
Resources

Install SOAP Toolkit

  1. Download a version of the SOAP Toolkit from Microsoft. I used version 2.0 and 2.0 SP2 for these tests.
  2. Follow the instructions in the installer. I installed to j:\program files 4\MSSOAP. The installer put the run-time files in j:\program files 4\common files\MSSOAP.
  3. Note the following about the SOAP Toolkit (from the readme.txt file)
    • The SOAP client objects will run on Windows 98, Windows ME, Windows NT 4.0 Service Pack 6, Windows 2000 Service Pack 1.
    • This release requires Internet Explorer 5.0 or 5.5.
    • The SOAP Toolkit 2.0 installation will install MSXML 3.0.
Return to top.

Run the Stock Quote client

  1. Download the Stock Quote client source.
  2. Unzip the downloaded file.
  3. Open the project named StockQuoteClient in Visual Basic and run it.

The stock quote client is a brute force application of the COM objects provided by the SOAP Toolkit. The code is as follows.

Option Explicit

Sub Main()
    Dim END_POINT_URL As String
    Dim Method As String
    Dim NS_URI_SOAP_ENC As String
    Dim STOCKQUOTE_NS As String
    Dim SOAP_ACTION As String
    Dim Connector As HttpConnector
    Dim Serializer As SoapSerializer
    Dim Reader As SoapReader
    
    ' In the Java client, this is the first parameter to call.invoke
    END_POINT_URL = "http://localhost:8080/soap/servlet/rpcrouter"
    ' Alternative for tracing
    'END_POINT_URL = "http://localhost:81/soap/servlet/rpcrouter"
    ' In the Java client, this is the parameter to call.setMethodName
    Method = "getQuote"
    ' In the Java client, this is the parameter to call.setEncodingStyleURI
    NS_URI_SOAP_ENC = "http://schemas.xmlsoap.org/soap/encoding/"
    ' In the Java client, this is the parameter to call.setTargetObjectURI
    STOCKQUOTE_NS = "urn:xmltoday-delayed-quotes"
    ' In the Java client, this is the second parameter to call.invoke
    'SOAP_ACTION = "uri:" & Method
    SOAP_ACTION = ""
    
    Set Connector = New HttpConnector
    Connector.Property("EndPointURL") = END_POINT_URL
    Connector.Connect 'Nothing - parameter used in beta versions of the Toolkit

    ' As of SOAP Toolkit 2.0 SP2, it is not legal to specify an empty SOAP_ACTION,
    ' but the same affect is achieved by not setting
    If Len(SOAP_ACTION) > 0 Then Connector.Property("SoapAction") = SOAP_ACTION
    Connector.BeginMessage 'Nothing - parameter used in beta versions of the Toolkit
    
    Set Serializer = New SoapSerializer
    Serializer.Init Connector.InputStream

    Serializer.startEnvelope
        Serializer.SoapAttribute "xmlns:xsi", , _
                                 "http://www.w3.org/1999/XMLSchema-instance"
        Serializer.SoapAttribute "xmlns:xsd", , _
                                 "http://www.w3.org/1999/XMLSchema"
        Serializer.startBody
            Serializer.startElement Method, STOCKQUOTE_NS, NS_URI_SOAP_ENC, "sq"
                ' In the Java client, this corresponds to a new Parameter(...)
                Serializer.startElement "symbol"
                    Serializer.SoapAttribute "xsi:type", , "xsd:string"
                    Serializer.writeString "IBM"
                Serializer.endElement
            Serializer.endElement
        Serializer.endBody
    Serializer.endEnvelope

    Connector.EndMessage

    Set Reader = New SoapReader
    Reader.Load Connector.OutputStream

    If Not Reader.Fault Is Nothing Then
        MsgBox Reader.faultstring.Text, vbExclamation
    Else
        MsgBox Reader.RPCResult.Text
    End If
End Sub
Return to top.

Trace the Stock Quote client

The TcpTunnelGui utility, included in Apache SOAP, is invaluable is seeing what characters are being sent and received by the client.

  1. Start TcpTunnelGui by running java org.apache.soap.util.net.TcpTunnelGui 81 localhost 8080
  2. In the VB code, change END_POINT_URL to http://localhost:81/soap/servlet/rpcrouter.
  3. Run the Stock Quote client again.

The client sends the following (formatting changed for readability):

POST /soap/servlet/rpcrouter HTTP/1.1
Content-Type: text/xml
Host: localhost
SOAPAction: ""
Content-Length: 457

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
                   xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
                   xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body>
<sq:getQuote xmlns:sq="urn:xmltoday-delayed-quotes"
             SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<symbol xsi:type="xsd:string">
IBM
</symbol>
</sq:getQuote>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

The (formatted) response from the server is:

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: 479
Date: Wed, 03 Apr 2002 17:00:50 GMT
Server: Apache Tomcat/4.0.1 (HTTP/1.1 Connector)
Set-Cookie: JSESSIONID=F51180227229B8B1B12340820094C2D3;Path=/soap

<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
                   xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
                   xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body>
<ns1:getQuoteResponse xmlns:ns1="urn:xmltoday-delayed-quotes"
            SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<return xsi:type="xsd:float">
99.93
</return>
</ns1:getQuoteResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Return to top.

Run the Address Book client

  1. Download the Address Book client source.
  2. Unzip the downloaded file.
  3. Open the project named AddressBookClient in Visual Basic and run it.

The address book client is based on a set of Visual Basic classes that in many ways mimic classes in Apache SOAP.

Return to top.

Resources

SOAP Interoperability with Microsoft and Apache Toolkits - A step by step guide, which shows an Apache client to a VB service.
Accessing a .NET Web Service using Apache/SOAP and Java, although I hope there is an easier way!

Return to top.

Copyright © 2002 Scott Nichol.
03-Apr-2002