Tutorials » Creating a Web Service using ActiveX Components

SOAP Client

For our SOAP Client we will create the following

  1. ActiveX Server Component
  2. ASP application to input a number and display the result.

ActiveX Server Component

  1. Create a new ActiveX dll Project
  2. Change the name of your project to SoapClient
  3. Change the name of your class to CreateSoap
  4. Add references to SOAP Type Library.

*For this example I use the SOAP Type Library v3.0.

The SOAP Client will accept the method call "CalcFactorial" or "CalcSquareRoot" and a user defined number from our ASP application "math.asp" Using the SOAP Serializer we will build a SOAP Envelope and send it to the SOAP Server via an http connector. The two possible outcomes from our SOAP Server are :

1. The answer via SOAP Message
2. A SOAP Fault alerting us of an error.

Code for CreateSoap.cls

' This is the Location of the asp listener page. In my case: localhost/SOAP/.

Const END_POINT_URL = "http://localhost/SOAP/SOAPListener.asp"

Public Function GenerateSOAP(ByVal MethodCall As String, ByVal num As Long) _
          As String
    Dim SOAPReader As MSSOAPLib30.SOAPReader30
    Dim SOAPSerializer As MSSOAPLib30.SOAPSerializer30
    Dim SOAPConnector As MSSOAPLib30.SOAPConnector30

    Set SOAPConnector = New MSSOAPLib30.HttpConnector30
    SOAPConnector.Property("EndPointURL") = END_POINT_URL

    ' Set Method Call

    SOAPConnector.Property("SoapAction") = MethodCall

    Set SOAPSerializer = New MSSOAPLib30.SOAPSerializer30
    SOAPSerializer.Init SOAPConnector.InputStream

    ' Create/Send SOAP Message with Parameter "Number"

        SOAPSerializer.StartElement MethodCall, "uri:Math", , "Functions"
          SOAPSerializer.StartElement "Number", "uri:Math", , "Functions"
            SOAPSerializer.WriteString num


    Set SOAPReader = New MSSOAPLib30.SOAPReader30

    ' Load SOAP Server response into reader

    SOAPReader.Load SOAPConnector.OutputStream

    ' Check for SOAP Fault. In most cases we would do something with a fault (log, etc.)
    ' For simplicity simply return to caller.

    If Not SOAPReader.Fault Is Nothing Then
        GenerateSOAP = SOAPReader.FaultString.Text
        GenerateSOAP = SOAPReader.RpcResult.Text
    End If
End Function

Previous Start Next
  1 2 3 4 5 6