[ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ 8 ] [ 9 ]

Creating a Web Service from a COM object

Let's start by creating a simple COM component with a few methods and calling it from a client application using the ROPE proxy object.  The COM object looks like this starting with the mandatory HelloWorld method:

    #DEFINE CRLF  CHR(13)+CHR(10)
     
    *************************************************************
    DEFINE CLASS SoapServer AS Session OLEPUBLIC
    *************************************************************
     
    ************************************************************************
    * SoapServer :: HelloWorld
    ****************************************
    FUNCTION helloworld(lcName as String) AS String
    RETURN "Hello World from " + GETENV("COMPUTERNAME") + ", " + lcName + "! Time is: " + TIME()
     
    ************************************************************************
    * SoapServer :: Evaluate
    ****************************************
    PROCEDURE evaluate( lcCommand as String)  AS Variant
       RETURN EVALUATE(lcCommand)
    ENDPROC
     
    ************************************************************************
    * SoapServer :: GetXML
    ****************************************
    ***  Function: Demonstrates returning XML results
    ***      Pass: lcName - Name to wrap in XML
    ***    Return:
    ************************************************************************
    PROCEDURE getxml(lcName as String) as String
     
    lcXML = [<?xml version="1.0"?>] + CRLF +;
             [<docroot>] + CRLF+;
             [  <name>] + lcName + [</name>] + CRLF + ;
             [</docroot>] + CRLF
     
    RETURN lcXML
     
    ************************************************************************
    * SoapServer :: GetXML
    ************************************************************************
    PROCEDURE getxmlcdata(lcName as String) as String
     
    lcXML = [<?xml version="1.0"?>] + CRLF +;
             [<docroot>] + CRLF+;
             [  <name><![CDATA[] + lcName + CHR(13) + CHR(10) + lcName + "]]</name>" + CRLF + ;
             [</docroot>] + CRLF
    RETURN lcXML
     
    PROCEDURE getobject(lnValue as Long, lcString as String, ldDate as Datetime) ;
             as soapdemo.retObject
     
    loCustom = CREATEOBJECT("soapdemo.retObject")
    loCustom.nValue = lnValue
    loCustom.cString = lcString
    loCustom.dDate = ldDate
    RETURN loCustom
     
    ENDDEFINE
     
    DEFINE CLASS retObject as Relation OLEPUBLIC
    nValue = 0
    cString = ""
    dDate = { : } 
     
    ENDDEFINE

Figure 2 – The SDL Wizard asks for a COM component to import

The first step is to pick a COM componet that the Wizard will work with. The Wizard will generate one SDL file for each class you select from the next dialog:

 

Figure 2 – The SDL Wizard lets you pick which methods to expose via the Web Service. Each COM class/interface you select is generated into a separate SDL and ASP file.

Notice the red methods in Figure 2. These methods mean that the parameters and return types were not set up with specific types but use variants instead. SOAP will allow you to use variant parameters but they will always be returned as Text rather than by their variant types. For example, the above evaluate method takes a string input parameter but a variant output parameter so we can return any result that our COM object can EVAL to (a string, a date or numeric value etc.). If a numeric value is returned SOAP will return the number but it will be returned as a string. The same goes for dates and logical values (1 or 0 for True and False respectively).

In the final two steps you need to tell the Wizard where your Web service will be located:

 

Figure 3 – You have to specify the HTTP location where the Web service will be accessed from. This Web virtual directory must already exist – the Wizard will not create it.

 

Figure 4 – This dialog requests the physical location for the file that the Wizard will generate. Again this directory must exist and should be the physical directory of the Web location chosen in the previous step.  

[ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ 8 ] [ 9 ]