Web Services & Mathematica

Christopher Williamson
chrisw@wolfram.com
Wolfram Research Inc.
March 2003

What are Web Services?

Programmatic interfaces made available on the network which are used for application to application communication.

Web Service Examples

Web Services Technology Used For Today's Demonstration

Extensible Markup Language (XML)

Hypertext Transfer Protocol (HTTP)

Simple Object Access Protocol (SOAP)

Web Service Definition Language (WSDL)

Other technologies such as SMTP and UDDI may be used with Web Services as well.

Why use XML and HTTP?

A user interacts with the web service interfaces by sending an XML messages over HTTP.

XML and HTTP are nice for creating and sending these messages because they are flexible and widely supported on many platforms and languages.

Promotes interoperability between applications and allows applications using differing languages and platforms to interface with one another.

What is SOAP?

SOAP is a Web Service API which formally sets the conventions governing the format and processing rules of an XML message.

SOAP is important because it standardizes the XML message used by the applications to communicate.

Without SOAP or a similar protocol, applications would not know how to process the XML messages.

What is WSDL?

WSDL is a Web Service API which formally sets the format for describing a Web Service.

By providing a URI to a WSDL file, applications can discover what the XML message for a particular operation look like, bind to it, and use it.

An operation may be used without a WSDL, however, the WSDL is key for promoting a Web Service.

Introducing the Mathematica WebServices package!

Dynamically and uniformly access data and functionality defined in other languages and on other platforms in Mathematica.

Goals of the WebServices package

Leverage existings technologies when available

Support the entire SOAP specification

Support the entire WSDL specification

Create a Java independent interface

Create a Mathematica interface that is familiar and unintimidating to Mathematica users.

Installing and Using a Web Service with a WSDL

<< WebServices`

InstallService["http://www.xmethods.net/sd/BabelFishService.\
wsdl"]

?BabelFish

BabelFish["en_de",  "Hello.  How are you?"]

InstallService["http://soap.amazon.com/schemas/\
AmazonWebServices.wsdl"]

?AuthorSearchRequest

\(AuthorSearchRequest[{"author" -> "Stephen Wolfram", \ "page" -> "1", \ "mode" -> \ "books", \ "tag" -> "webservices-20", "type" -> "lite", \ "devtag" -> "D3VZJS46JD5U9D", \ \ "version" -> "1.0"}]\)

What does InstallService do?

1. Retrieve the WSDL file from a http source using XML`Parser`XMLGet.

2. Uses definitions in the WSDL file to map binding information to options.

3. Uses definitions in the WSDL file to define parameters for a function.

4. Uses definitions in the WSDL file to map information to be used to generate an OperationPalette.

5. Uses InstallServiceOperation to define Mathematica functions.

6. Uses InstallServiceOperation to define Mathematica message functions.

Rule Syntax vs. Symbolic XML

InstallService["http://terraservice.net/TerraService.asmx?WSDL \
"]

ConvertUtmPtToLonLatPt[{"Zone" -> 47, "X" -> 
          480615.19670402736, "Y" -> 11114177.470906643}]

StringLength[ToString[Hold[\(AuthorSearchRequest[{
"author" -> "Stephen Wolfram", \ "page" -> "1", \ "mode" -> \ "books", \ "tag" -> "webservices-20", "type" -> "lite", \ "devtag" -> "D3VZJS46JD5U9D", \ \ "version" -> "1.0"}]\)]]]

StringLength[ToString[Hold[\(AuthorSearchRequest[{
XMLElement["author", {}, {"Stephen Wolfram"}], \ 
                XMLElement["page", {}, {"1"}], \ 
                XMLElement["mode", \ {}, \ {"books"}], \ 
                XMLElement["tag", {}, \ {"webservices-20"}], 
                XMLElement["type", \ {}, \ {"lite"}], \ 
                XMLElement["devtag", \ {}, {"D3VZJS46JD5U9D"}], \ \ XMLElement["version", {}, \ {"1.0"}]}]\)]]]

InstallService["http://soap.amazon.com/schemas/\
AmazonWebServices.wsdl"]

\(AuthorSearchRequest[{{{"urn:PI/DevCentral/SoapService", "author"}, {{"http://www.w3.org/2001/XMLSchema-instance", "type"} -> {"http://www.w3.org/1999/XMLSchema", "string"}}} -> "Stephen Wolfram", {{"urn:PI/DevCentral/SoapService", "page"}, {{"http://www.w3.org/2001/XMLSchema-instance", "type"} -> {"http://www.w3.org/1999/XMLSchema", "string"}}} -> "1", {{"urn:PI/DevCentral/SoapService", "mode"}, {{"http://www.w3.org/2001/XMLSchema-instance", "type"} -> {"http://www.w3.org/1999/XMLSchema", "string"}}} -> "books", {{"urn:PI/DevCentral/SoapService", "tag"}, {{"http://www.w3.org/2001/XMLSchema-instance", "type"} -> {"http://www.w3.org/1999/XMLSchema", "string"}}} -> "webservices-20", {{"urn:PI/DevCentral/SoapService", "type"}, {{"http://www.w3.org/2001/XMLSchema-instance", "type"} -> {"http://www.w3.org/1999/XMLSchema", "string"}}} -> "lite", {{"urn:PI/DevCentral/SoapService", "devtag"}, {{"http://www.w3.org/2001/XMLSchema-instance", "type"} -> {"http://www.w3.org/1999/XMLSchema", "string"}}} -> "D3VZJS46JD5U9D", {{"urn:PI/DevCentral/SoapService", "version"}, {{"http://www.w3.org/2001/XMLSchema-instance", "type"} -> {"http://www.w3.org/1999/XMLSchema", "string"}}} -> "1.0"}, 
      LongForm -> True]\)

Benefits of the design

Minimal knowledge of XML, HTTP, SOAP, or WSDL is required.

Automatically extracts results from the response message.

Automatic type conversion using WSDL definitions.

Advanced SOAP Functions

InstallService["http://www.xmethods.net/sd/2001/CATrafficService.wsdl\
"]

Retrieve the request message generated for this call or build one from scratch...

request  =  ToServiceRequest[getTraffic, "101"]

Customize the request message...

\(request\  = \ 
      request\  /. \ \((XMLElement[{"", "hwynums"}, {{"xsi", "type"} -> "xsd:string"}, {"101"}])\)\  -> \ \((XMLElement[{"", "hwynums"}, {{"xsi", "type"} -> "xsd:string", \ "attrib" -> "value"}, {"101"}])\)\)

Invoke the message...

response  =  getTraffic[request]

Process the response...

FromServiceResponse[response]

Alternately retrieve the response message...

response  =  InvokeServiceOperation[getTraffic,  request]

And process the response...

FromServiceResponse[response]

1. Build the request message...

\(msg\  = \ 
      ToServiceRequest[{{"zipcode", {{"http://www.w3.org/2001/XMLSchema-instance", \ "type"} -> {"http://www.w3.org/2001/XMLSchema", "string"}}} -> "61821"}, {}, \ 
OperationName -> {"urn:xmethods-Temperature", "getTemp"}]\)

2. Invoke...

response  =  
      InvokeServiceOperation["http://services.xmethods.net:80/soap/servlet/\
rpcrouter",  msg]

3. Process the Response...

FromServiceResponse[response]

Optionally install for a simple, reusable interface...

\(InstallServiceOperation[
      TempService`getTempFromZipCode, \ "http://services.xmethods.net:80/soap/servlet/rpcrouter", \ 
{{"zipcode", {{"http://www.w3.org/2001/XMLSchema-instance", \ "type"} -> {"http://www.w3.org/2001/XMLSchema", "string"}}}}, {}, 
      OperationName -> {"urn:xmethods-Temperature", "getTemp"}]\)

getTempFromZipCode["61821"]

Packaged Examples

Amazon Web Service

XMethods Query Web Service

TerraService

Providing Wolfram Web Services

Examples of Wolfram Web Services

Functions.wolfram.com Web Service

Integrate Web Service

Future of Web Services & Mathematica

<< WebServices`Examples`Menu`

Who? What? Where? When?

The WebServices package will be available soon as a Beta product.

Questions and inqueries can be sent to chrisw@wolfram.com.