Testing the SOAP Connection
To test the connection, a simple VBScript file will be used. It will use the Microsoft SOAP client object to open a connection to the server and call the ProcessOrder() method on the OrderHandler object. Listing 2 shows the contents of the SOAP test script in OrderHandlerSOAPTest.vbs.
Listing 2The SOAP Server Test Script
Option Explicit Dim soapClient Set soapClient = CreateObject("MSSOAP.soapClient") On Error Resume Next soapClient.mssoapinit "http://localhost/OrderHandler/OrderHandler.wsdl",_ "OrderHandler", "OrderHandlerSoapPort" If Err <> 0 Then wscript.echo "initialization failed " + Err.description End If wscript.echo soapClient.ProcessOrder("Customer One", "223234234",_ "customer@strategicxml.com", "2/2/01", Array("Q123", "B234"), Array(2, 5)) If err <> 0 Then wscript.echo Err.description wscript.echo "faultcode=" + soapClient.faultcode wscript.echo "faultstring=" + soapClient.faultstring wscript.echo "faultactor=" + soapClient.faultactor wscript.echo "detail=" + soapClient.detail End If
This script creates and initializes an instance of the Microsoft soapClient object. The URL location of the WSDL file is set to the local host in the OrderHandler virtual directory. In addition to specifying the location of the WSDL file, the mssoapinit() method takes the name of the SOAP service requested as well as the port name (both items are declared in the WSDL file).
After the SOAP connection is initialized successfully, the ProcessOrder() operation is invoked with a set of test parameters. Notice that the Array() VBScript function is used to create the temporary arrays that contain the part numbers and quantities for the order. If an error occurs during the request, the script uses the wscript.echo() method to report it to the console. To run this script, double-click it from the Windows shell or run it from the command line:
c:\Sams\StrategicXML\Chapter15Project>cscript OrderHandlerSOAPTest.vbs
The cscript executable runs the script as a console script, which causes output to be echoed to standard output. If the script is run through the shell, the wscript.echo() method output will be displayed using a Windows message box.