| External Interfaces | ![]() |
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:
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.
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:
@TemperatureService folder. In the folder, you see the following files:
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
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:
@TemperatureService, in the current MATLAB directory
getTemp.m, display.m, and TemperatureService.m, based on the service API
For more information about object-oriented programming in MATLAB, see the MATLAB Programming documentation.
| Finding More Information About Web Services | Building MATLAB Applications with Web Services | ![]() |
© 1994-2005 The MathWorks, Inc.