Using Microsoft SOAP ToolKit

Snoops

   

 
Migrating to .NET: A Pragmatic Path to Visual Basic .NET, Visual C++ .NET, and ASP.NET
By Dhananjay Katre, Prashant Halari, Narayana Rao Surapaneni, Manu Gupta, Meghana Deshpande

Table of Contents
Chapter 11.  Exposing Legacy Components as Web Services


The SOAP ToolKit 2.0 creates WSDL and WSML files for a given COM component. The WSDL file specifies what the request message must contain and what the response message will look like as well as the protocol used in communication. The WSML file contains information used by SoapServer to map information from the COM object to the Web service. The SoapServer is created in a listener application.

The listener is a separate application at the Web service end that is created independently of the component used to catch and process the document sent by a client. The SOAP listener is the SOAP message processor. Two implementations of the SOAP listener are provided in the SOAP ToolKit along with the code. One implementation is written as an ASP script, and the other is a custom-built ISAPI extension. The SOAP listener provides a point of entry for clients to access the Web service. The SOAP Toolkit 2.0 includes SoapServer, which is used in a listener application to process SOAP documents.

At the client end, SoapClient is used to actually access the Web service. SoapClient will not only create a SOAP document to communicate with a Web service, but it will also send the document to the Web service for processing.

The following example exposes a COM DLL named MyComp that contains the class MyClass and method GetMessage :

  1. In the SOAP ToolKit 2.0 wizard enter the name you wish for your WSDL file. Enter the path of the existing COM dll or browse and point to the COM. See Figure 11-1.

    Figure 11-1. Select COM for conversion.

    graphics/11fig01.gif

  2. Select methods within the class that you wish to expose through the Web service. See Figure 11-2. The preceding example contains only one method GetMessage , which is selected as shown.

    Figure 11-2. Select methods to be exposed.

    graphics/11fig02.gif

  3. Select the appropriate listener. See Figure 11-3. It provides the SOAP functionality for the Web service. Using the ToolKit, the SOAP listener can be implemented as an ASP file, an ISAPI extension, or a custom-built listener. We select ASP listener for our case. The SOAP ToolKit creates a listener file named WSDLfromCOM.asp .

    Figure 11-3. Select listener.

    graphics/11fig03.gif

  4. Browse and select the location for the WSDL and WSML files. See Figure 11-4. The listener file is stored at the same path.

    Figure 11-4. Select location for created files.

    graphics/11fig04.gif

The WSDL file generated through SOAP ToolKit follows :

 graphics/icon01.gif <?xml version='1.0' encoding='UTF-8' ?>   <!-- Generated 05/10/02 by Microsoft SOAP Toolkit WSDL File  Generator, Version 1.02.813.0 -->  <definitions name ='WSDLfromCOM'   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/soaptool_       kit/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='MyClass.GetMessage'>    </message>    <message name='MyClass.GetMessageResponse'>      <part name='Result' type='xsd:string'/>    </message>    <portType name='MyClassSoapPort'>      <operation name='GetMessage' parameterOrder=''>        <input message='wsdlns:MyClass.GetMessage' />        <output message='wsdlns:MyClass.GetMessageResponse'        />      </operation>    </portType>    <binding name='MyClassSoapBinding' _    type='wsdlns:MyClassSoapPort' >      <stk:binding preferredEncoding='UTF-8'/>      <soap:binding style='rpc' trans      port='http://schemas.xmlsoap.org/soap/http' />      <operation name='GetMessage' >        <soap:operation soapAc_         tion='http://tempuri.org/action/MyClass.GetMessage'         />        <input>          <soap:body use='encoded' name_          space='http://tempuri.org/message/'          encoding _          Style='http://schemas.xmlsoap.org/soap/encoding/'          />        </input>        <output>          <soap:body use='encoded' name           space='http://tempuri.org/message/'             encoding             Style='http://schemas.xmlsoap.org/soap/             encoding/' />        </output>      </operation>    </binding>    <service name='WSDLfromCOM' >      <port name='MyClassSoapPort' bind      ing='wsdlns:MyClassSoapBinding' >        <soap:address location='http://WSDLfromCOM.ASP'/>      </port>    </service>  </definitions> 

The WSDL file defines the request message with data types for each of its parameters and its response along with the data types. In this case, the request message doesn't have any parameters, and the data type for the response message is a string. The data types in the COM object that cannot be converted through the SOAP ToolKit are created as String in the WSDL file. This file can later be edited to make necessary changes to the data types. The servicename section of the WSDL file points to the SOAP listener, in our case WSDLfromCOM.asp . The SOAP address location is edited to point to this file:

 <soap:address location='http://localhost/CodeSamples/WSDLfrom- COM.ASP'/> 

If ISAPI listener is implemented, this location name will point to the WSDL file itself. The listener file WSDLfromCOM.asp is created as follows:

 graphics/icon01.gif <%@ LANGUAGE=VBScript %>  <%  Option Explicit  On Error Resume Next  Response.ContentType = "text/xml"  Dim SoapServer  If Not Application("WSDLfromCOMInitialized") Then    Application.Lock    If Not Application("WSDLfromCOMInitialized") Then      Dim WSDLFilePath      Dim WSMLFilePath      WSDLFilePath = Server.MapPath("WSDLfromCOM.wsdl")      WSMLFilePath = Server.MapPath("WSDLfromCOM.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("WSDLfromCOMServer") = SoapServer      Application("WSDLfromCOMInitialized") = True    End If    Application.UnLock  End If  Set SoapServer = Application("WSDLfromCOMServer")  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 administrator. " & LogMes_       sage        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  %> 

The important part of code is the place where it creates and initializes the SOAPServer :

 graphics/icon01.gif Dim WSDLFilePath  Dim WSMLFilePath  WSDLFilePath = Server.MapPath("WSDLfromCOM.wsdl")  WSMLFilePath = Server.MapPath("WSDLfromCOM.wsml")  Set SoapServer = _  Server.CreateObject("MSSOAP.SoapServer")  SoapServer.Init WSDLFilePath, WSMLFilePath  SoapServer.SoapInvoke Request, Response, "" 

To initialize the SOAPServer, the paths of WSDL and WSML files are provided. These paths are specified in the ToolKit during their creation. Thus, the service description for the Web service is ready. Now all that needs to be done is to consume the Web service in a client application.


Snoops

   
Top


Migrating to. NET. A Pragmatic Path to Visual Basic. NET, Visual C++. NET, and ASP. NET
Migrating to. NET. A Pragmatic Path to Visual Basic. NET, Visual C++. NET, and ASP. NET
ISBN: 131009621
EAN: N/A
Year: 2001
Pages: 149

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net