Your First SOAP call

This introduces the basics, and shows how to make simple SOAP calls, we'll walk through calling the XMethods stock quote service.

Information needed

Before writing the code to make the call, you'll typically need to collect the following information
Looking at the description page for the stock quote service, we can use the View RPC Profile link to find out the we need (go ahead and pop the RPC Profile Window up)


Here's a sample to make the above call, this is in VBScript.

' Create a new envelope object, this is the core part of any pocketSOAP usage.
dim env
set env = CreateObject("pocketSOAP.Envelope.11")

' set the methodName and methodname Namespace values
env.SetMethod "getQuote", "urn:xmethods-delayed-quotes"

' create the parameter, we'll ask for a quote for [their ticker is CRM]
env.Parameters.Create "symbol", "CRM"

' now, we need to send the SOAP request to the endpoint, so we create a transport object
dim http
set http = CreateObject("pocketSOAP.HTTPTransport")

' we need to set the SOAPAction header
http.SOAPAction = "urn:xmethods-delayed-quotes#getQuote"
' now we send the request, this takes the envelope object we've been working with
' and serializes it out over the HTTP request
http.Send "", env

' now, we need to parse the SOAP message we get as a response
env.parse http

' and now, extract the return value
wscript.echo "Quote for CRM = " & env.Parameters.Item(0).Value
Running this code generates this output [obviously the actual value will be different when you run it !]
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

Quote for CRM = 18.39
Congratulations, you've just writen your first SOAP client, and not a single angle bracket in sight! Simple eh ?, no messing around with XML, all the grungy stuff is safely hidden away !

So what did we actually send to the XMethods server ?

So, you want to see what the actual SOAP request/response messages look like, there's a couple of ways to do this, the easiest is to use a HTTP trace tool. Grab a copy of ProxyTrace this is a simple HTTP proxy server I wrote that shows the request/response going through it.

Open the zip file, and drop proxyTrace.exe on your desktop an start it. You be prompted with a dialog box that asks "Listen on Port #" leave it on the default of 8080 and hit OK. Now go back to the above code and insert before the call the http.send this line
http.SetProxy "localhost", 8080
Re-running the script should give the same results, but now you'll see that proxyTrace has an item in the left hand list view. Click on the item in the list, the right hand view will change to show the request [at the top], and the response [at the bottom]


Copyright © Simon Fell, 2000-2004. All rights reserved.