Basic Examples of Web Services
|Mathematical Data: Integrate||Timeouts|
Often a web service requires using data other than a simple string. This data could be something simple like an integer or a real. Often the data is more complex and is a combination of simple data types. This example demonstrates how to use different data types.
Simple data types are the easiest data types to use in Web Services Link. Wolfram Language users should be familiar with the symbols String, Integer, Real, True, and False. Each of these may be used with a web service function.
Here is an example of using True with a web service.
Here is an example of using String with a web service.
Here is an example of using Integer with a web service.
Here is an example of using Real with a web service.
Web Services Link provides some data types that may be mapped to the XML Schema of a web service. SchemaDate, SchemaTime, SchemaDateTime, SchemaExpr, SchemaMathML, and SchemaBase64Binary are each simple data types that may be used with a web service.
Web Services Link generates symbols that are used to build compound data types. Compound data types are Wolfram Language expressions that contain instances of simple data types and/or compound data types. Compound data types are created in the Wolfram Language using a symbol representing the data type as the head of a Wolfram Language expression. The members of the data type are represented using rules in the body of the expression. The left-hand side of the rule specifies the name of a member of the data type. The right-hand side specifies the value of the member. The value may be a simple or compound value.
In the Plot example, PlotString takes a string and an integer as parameters and returns a base64 binary string. The function converts the string into a Wolfram Language expression and then plots this as a function of from 0 to a limit specified by the integer. The service returns a list of base64 binary bytes wrapped in a head of SchemaBase64Binary. This head is used to identify this data as base64 binary. FromCharacterCode can be used to decode the base64 binary data into a string consisting of GIF data. This string may be imported to a GIF with ImportString.
Mathematical data can be used with a web service by using Wolfram Language expressions within a string. The string data type has some limitations for communicating mathematical data. For one, it is one-dimensional. If you use InputForm or FullForm to represent the data, information about its presentation may be left out. It is also worth noting that while all web services support strings, they may not all support parsing Wolfram Language expressions from a string. However, sending a string to web service is probably the simplest way to communicate mathematical data, if not the most advanced.
Mathematical data can be presented with a web service by using images. An image has one major limitation for communicating mathematical data. An image cannot be easily manipulated or processed. This means data cannot be easily taken from it except visually and it cannot be changed and updated easily. Images are often useful, however, because typeset equations are not supported on nearly as many systems as images. So generating an image of a typeset equation is a nice way to present typeset equations on systems that do not support them.
The following example demonstrates using images to communicate mathematical data. The service returns a list of base64 binary bytes wrapped in a head of SchemaBase64Binary. This head is used to identify this data as base64 binary. FromCharacterCode can be used to decode the base64 binary data into a string consisting of GIF data. This string may be imported to a GIF with ImportString.
Mathematical data can be presented with a web service by using Wolfram Language expressions. Expressions are how data is represented in the Wolfram Language. Expressions address some of the limitations of strings and images. However, expressions do have a few limitations of their own, the biggest being that they are not supported on all systems. However, since expressions are the standard for using mathematical data with the Wolfram Language, they can be very useful for interfacing with other Wolfram Language systems.
The following example demonstrates using Wolfram Language expressions to communicate mathematical data. The service returns an expression wrapped in a head of SchemaExpr. This head is used to identify the following data as an expression.
Mathematical data can be presented with a web service by using MathML. MathML is the standard for representing mathematical data across systems. MathML addresses some of the limitations that strings and images have. However, MathML does have a few limitations of its own, the biggest being that it is not supported on all systems. Another limitation is its complexity. MathML is more difficult to look at than something like InputForm. However, since it is the standard for using mathematical data outside of the Wolfram Language, it can be very useful for interfacing with other systems that do not use the Wolfram Language.
Web Services Link does not take a MathML expression and automatically convert it into a Wolfram Language expression, because not all MathML instances are necessarily supported by Wolfram Language expressions. But because this is the Wolfram Language, the result can easily be turned into an expression.
SOAP headers are an important component to web services because they allow web services to process metadata separate from the body of a SOAP message. The body will contain information directly related to the web service operation being invoked. However, a header may contain more general content that is used across any number of the web service operations. For example, a header may contain a username and password. It is useful to include the username and password as a header, because a separate component can be used to process the username and password without needing to know anything about the body.
Web Services Link supports headers by including the header as part of the function signature of an operation. So it will look like any other parameter of the operation. If an operation requires two strings defining the username and password as headers, then these two strings will be expected when calling this function.
Sessions are used by web services to persist user data over multiple calls to a web service. For example, they can be used to save a user's settings, data, or other things. Sessions are supported by Web Services Link. However, there are no special functions or options. If a web service provides operations that use sessions, then sessions should be used by the Java client.
Authentication is used by some web services to validate a user. This is based on functionality provided by HTTP. Digest and basic authentication are supported. A user can set the username and password by using the Username and Password options. These can be passed into any web service function and used for authentication.
A timeout may be required when calling a web service operation. A user can set the timeout by using the Timeout option. This can be passed into any web service function. The value of the option must be a positive integer specifying the timeout in milliseconds.