Web Services Workshop

Chris Williamson

Wolfram Research

What are Web Services?

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

What are Web Services?

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

Language and Platform independent

What are Web Services?

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

Language and Platform independent

Generally invoked similar to how any other Mathematica functions.

What are Web Services?

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

Language and Platform independent

Generally invoked similar to how any other Mathematica functions.

Useful for calling remote functionality.

What are web services?

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

Language and Platform independent

Generally invoked similar to how any other Mathematica functions.

Useful for calling remote functionality.

Useful for querying data from a remote machine.

How do web services work?

Send XML messages over HTTP to the server.

How do web services work?

Send XML messages over HTTP to the server.

Use SOAP to encode and process the messages.

How do web services work?

Send XML messages over HTTP to the server.

Use SOAP to encode and process the messages.

Use WSDL to discover and bind to the interface for the web service.

Load the Package

The package needs to be loaded before we can use WebServices.

<< WebServices`

Install a web service

A web service can be installed by pointing InstallService to a WSDL file.  This function returns a list of functions.

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

Simple Example

If content is provided by the web service, the usage message for a function describes the purpose of the web service.  It also provides a link to the OperationPalette.  The OperationPalette can be used to inspect the function.  It can retrieve parameters and datatypes used with the function.

?getTemp

Simple Example (con't)

The function may be invoked using the parameters described by the OperationPalette.  Online documentation may also be very useful for determining how a web service works.

getTemp["61821"]

Exercise 1 - Check the price of an auction on Ebay

Using http://www.xmethods.net/sd/2001/EbayWatcherService.wsdl, find the current price of an auction.  Example auction ids are 2279166114 and 5132857490.  Documentation for this web service may be found here.

Exercise 2 - Morse Code

Using http://www.regomnet.de/morse.asmx?WSDL, translate the phrase "Mathematica is fun" into MorseCode.  Translate it back into text if you like.  Documentation for this web service may be found here.

Exercise 3 - Get a stock quote

Using http://www.swanandmokashi.com/HomePage/WebServices/StockQuotes.asmx?WSDL, find the latest stock quote for Motorola (MOT).  Documentation for this web service may be found here.

Working with compound types

Compound data types are structures of data that make up combinations of simple data types (strings, integers, reals, etc.)

Working with compound types

Compound data types are structures of data that make up combinations of simple data types (strings, integers, reals, etc.)

Most useful web services use compound data types.

Working with compound types

Compound data types are structures of data that make up combinations of simple data types (strings, integers, reals, etc.)

Most useful web services use compound data types.

Compound data types use a rule syntax.

Compound Example

InstallService can be used to install the service.  Once it is installed we can look at the usage message and OperationPalette.  The OperationPalette lets you explore the compound types and paste a template of compound types into a notebook.

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

?AuthorSearchRequest

Compound Example (con't)

The values of the compound datatypes can be input using a rule form.  One compound datatype in rule form is essentially a list of rules specifying names and values.  Values may consist of simple datatypes or compound datatypes.  One thing to note is the more complex a web service, the more online documentation will help you.  Most of these values were helped along using online documentation.

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

Compound Example (con't)

Of course once data is in Mathematica, Mathematica functions can be used to transform and display the data.

ListPlot[
      Sort[ToExpression[StringDrop[#,  1]]  &  /@  
          Cases[results,  
            Rule["ListPrice", listPrice_String] :> 
              listPrice,  Infinity]],  PlotJoined -> True]

Exercise 4 - Use the Google web service

Using http://api.google.com/GoogleSearch.wsdl, find information about Mathematica's Web Services Package.  Also use Google to see if you can check the spelling of your query.  Documentation for this web service may be found here.  Use the key "3HB82PdQFHITKPmbmm5G/9aTfVHx/m95" or register for your own.

Exercise 5 - Use web services to find data about a location

Using http://terraservice.net/TerraService.asmx?WSDL, find the facts, latitude and longitude of a location.  Using http://www.winisp.net/cheeso/zips/ZipService.asmx?WSDL, find the zip code for the location.  Using http://www.xmethods.net/sd/2001/TemperatureService.wsdl, find the temperature of the location.  For extra credit display an image of the location using TerraService.  Documentation for TerraService may be found here.  Documentation for ZipService may be found here.  Documentation for ZipService may be found here.

Conclusion

Questions.

My email is chrisw@wolfram.com.