External Interfaces Previous page   Next Page

Using Web Services in MATLAB

In MATLAB, you use the createClassFromWsdl function to call Web service methods. The function creates a MATLAB class based on the methods of the Web service application program interface (API).

Here is an example of the createClassFromWsdl function using a URL:

In the example, a URL to a WSDL file is passed to the function. The following example uses a file path instead of a URL:

In the example, a relative file path is passed to the function. Keep in mind that the target file must contain WSDL.

The following procedure walks you through the necessary steps to build a simple Web service. To begin, the procedure shows you how to find the temperature the Web service used in previous examples:

  1. In a Web browser, go to the XMethods Web site at http://www.xmethods.net.

  2. In XMethods Demo Services, click on the Weather - Temperature link.
  3. On the Weather - Temperature Web page, you will find the WSDL URL, as well as links to analyze the WSDL. Click the View RPC Profile link.
  1. In the RPC Profile page, you will see the available methods. In this case, the available method is getTemp.

    In addition to the method name, you can see the input and output parameters and their data types. The output parameter returns a float data type. In Understanding Data Type Conversions, you see that MATLAB converts float to a double scalar.

  1. To use the createClassFromWsdl function, enter the following code at the MATLAB command line:
  1. You pass the WSDL URL to the createClassFromWsdl function. In response, MATLAB outputs

    This indicates that MATLAB has successfully parsed the WSDL and created the TemperatureService class. To view the methods associated with the TemperatureService class, enter the following code:

    MATLAB outputs

  1. In the current MATLAB directory, find the @TemperatureService folder. In the folder, you see the following files:
  1. The createClassFromWsdl function automatically creates a file for each Web service method, a file for a generic display method, and a file for the Web service MATLAB object.

    You can use the MATLAB help function to see the method signature, such as

  1. Call the getTemp method with the following code:
  1. The getTemp method in MATLAB requires two arguments. It requires an instance of the TemperatureService class (ts) and the zip code (01760). In response, MATLAB outputs:

To review, the createClassFromWsdl function performs the following actions:

For more information about object-oriented programming in MATLAB, see the MATLAB Programming documentation.


Previous page  Finding More Information About Web Services Building MATLAB Applications with Web Services Next page

© 1994-2005 The MathWorks, Inc.