September 23, 2002

SOAP (Web service) using VB and ASP

Originally written on 9/23/2002

VB DLL code: (soapTest.vbp class- clsSOAP.cls)

Public Function getData(id As Long, name As String) As String

getData = id & " " & name & "!"

End Function


ASP Code: (Facade) (SoapTest1.asp)


< %@ LANGUAGE=VBScript %>
< % Option Explicit On Error Resume Next Response.ContentType = "text/xml" Dim SoapServer If Not Application("SoapTest1Initialized") Then Application.Lock If Not Application("SoapTest1Initialized") Then Dim WSDLFilePath Dim WSMLFilePath WSDLFilePath = Server.MapPath("SoapTest1.wsdl") WSMLFilePath = Server.MapPath("SoapTest1.wsml") Set SoapServer = Server.CreateObject("MSSOAP.SoapServer") If Err Then SendFault "Cannot create SoapServer object. " & Err.Description SoapServer.Init WSDLFilePath, WSMLFilePath If Err Then SendFault "SoapServer.Init failed. " & Err.Description Set Application("SoapTest1Server") = SoapServer Application("SoapTest1Initialized") = True End If Application.UnLock End If Set SoapServer = Application("SoapTest1Server") SoapServer.SoapInvoke Request, Response, "" If Err Then SendFault "SoapServer.SoapInvoke failed. " & Err.Description Sub SendFault(ByVal LogMessage) Dim Serializer On Error Resume Next ' "URI Query" logging must be enabled for AppendToLog to work Response.AppendToLog " SOAP ERROR: " & LogMessage Set Serializer = Server.CreateObject("MSSOAP.SoapSerializer") If Err Then Response.AppendToLog "Could not create SoapSerializer object. " & Err.Description Response.Status = "500 Internal Server Error" Else Serializer.Init Response If Err Then Response.AppendToLog "SoapSerializer.Init failed. " & Err.Description Response.Status = "500 Internal Server Error" Else Serializer.startEnvelope Serializer.startBody Serializer.startFault "Server", "The request could not be processed due to a problem in the server. Please contact the system admistrator. " & LogMessage Serializer.endFault Serializer.endBody Serializer.endEnvelope If Err Then Response.AppendToLog "SoapSerializer failed. " & Err.Description Response.Status = "500 Internal Server Error" End If End If End If Response.End End Sub %>


WSML Code: (SoapTest1.wsml) Replace # with <

#!-- Generated 09/23/02 by Microsoft SOAP Toolkit WSDL File Generator, Version 1.02.813.0 -->

#?xml version='1.0' encoding='UTF-8' ?>
#servicemapping name='SoapTest1'>
#service name='SoapTest1'>
#using PROGID='soapTest.clsSOAP' cachable='0' ID='clsSOAPObject' />
#port name='clsSOAPSoapPort'>
#operation name='getData'>
#execute uses='clsSOAPObject' method='getData' dispID='1610809344'>
#parameter callIndex='1' name='id' elementName='id' />
#parameter callIndex='2' name='name' elementName='name' />
#parameter callIndex='-1' name='retval' elementName='Result' />
#/execute>
#/operation>
#/port>
#/service>
#/servicemapping>


WSDL Code: (SoapTest1.wsdl) Replace # with <

#?xml version='1.0' encoding='UTF-8' ?>
#!-- Generated 09/23/02 by Microsoft SOAP Toolkit WSDL File Generator, Version 1.02.813.0 -->
#definitions name ='SoapTest1' targetNamespace = 'http://tempuri.org/wsdl/'
xmlns:wsdlns='http://tempuri.org/wsdl/'
xmlns:typens='http://tempuri.org/type'
xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/'
xmlns:xsd='http://www.w3.org/2001/XMLSchema'
xmlns:stk='http://schemas.microsoft.com/soap-toolkit/wsdl-extension'
xmlns='http://schemas.xmlsoap.org/wsdl/'>
#types>
#schema targetNamespace='http://tempuri.org/type'
xmlns='http://www.w3.org/2001/XMLSchema'
xmlns:SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/'
xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/'
elementFormDefault='qualified'>
#/schema>
#/types>
#message name='clsSOAP.getData'>
#part name='id' type='xsd:int'/>
#part name='name' type='xsd:string'/>
#/message>
#message name='clsSOAP.getDataResponse'>
#part name='Result' type='xsd:string'/>
#part name='id' type='xsd:int'/>
#part name='name' type='xsd:string'/>
#/message>
#portType name='clsSOAPSoapPort'>
#operation name='getData' parameterOrder='id name'>
#input message='wsdlns:clsSOAP.getData' />
#output message='wsdlns:clsSOAP.getDataResponse' />
#/operation>
#/portType>
#binding name='clsSOAPSoapBinding' type='wsdlns:clsSOAPSoapPort' >
#stk:binding preferredEncoding='UTF-8'/>
#soap:binding style='rpc' transport='http://schemas.xmlsoap.org/soap/http' />
#operation name='getData' >
#soap:operation soapAction='http://tempuri.org/action/clsSOAP.getData' />
#input>
#soap:body use='encoded' namespace='http://tempuri.org/message/'
encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' />
#/input>
#output>
#soap:body use='encoded' namespace='http://tempuri.org/message/'
encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' />
#/output>
#/operation>
#/binding>
#service name='SoapTest1' >
#port name='clsSOAPSoapPort' binding='wsdlns:clsSOAPSoapBinding' >
#soap:address location='http://127.0.0.1/soapListen/SoapTest1.ASP' />
#/port>
#/service>
#/definitions>



SOAP Client Code:

Private Sub Command1_Click()
Dim o As New soapClient
o.mssoapinit "http://localhost/soaplisten/soaptest1.wsdl"
MsgBox CStr(o.GetData(2, "b"))
End Sub