SOAP Client
For our SOAP Client we will create the following
ActiveX Server Component
*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 SOAPConnector.Connect ' Set Method Call SOAPConnector.Property("SoapAction") = MethodCall SOAPConnector.BeginMessage Set SOAPSerializer = New MSSOAPLib30.SOAPSerializer30 SOAPSerializer.Init SOAPConnector.InputStream
' Create/Send SOAP Message with Parameter "Number"
SOAPSerializer.StartEnvelope SOAPSerializer.StartBody SOAPSerializer.StartElement MethodCall, "uri:Math", , "Functions" SOAPSerializer.StartElement "Number", "uri:Math", , "Functions" SOAPSerializer.WriteString num SOAPSerializer.EndElement SOAPSerializer.EndElement SOAPSerializer.EndBody SOAPSerializer.EndEnvelope SOAPConnector.EndMessage 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 Else GenerateSOAP = SOAPReader.RpcResult.Text End If End Function