| MATLAB® | ![]() |
| On this page… |
|---|
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:
createClassFromWsdl('http://example.com/service.wsdl')
The example passes a URL to a WSDL file to the function. The following example uses a file path instead of a URL:
createClassFromWsdl('\myservicedirectory\service.wsdl')
The example passes a relative file path to the function. Keep in mind that the target file must contain WSDL.
Note To call remote Web services with MATLAB, you must have a working Internet connection. |
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 Currency Exchange Rate Web service:
In a Web browser, go to the XMethods Web site at http://www.xmethods.net/.
In XMethods Demo Services, click the Currency Exchange Rate link near the bottom of the page.
On the Currency Exchange Rate Web page, find the WSDL URL, as well as links to analyze the WSDL. Click the View RPC Profile link.
In the RPC Profile page, find the available methods. In this case, the available method is getRate.
In addition to the method name, notice the input and output parameters and their data types. The output parameter returns a float data type. In Understanding Data Type Conversions, note that MATLAB converts float to a double scalar.
Enter the following code at the MATLAB command line to pass the WSDL URL to the functioncreateClassFromWsdl, creating the CurrencyExchangeService class:
createClassFromWsdl(['http://www.xmethods.net/sd/2001' ...
'/CurrencyExchangeService.wsdl']);
ans =
CurrencyExchangeService
Use the MATLAB methods function to view the methods associated with the CurrencyExchangeService class:
methods(CurrencyExchangeService) Methods for class CurrencyExchangeService: CurrencyExchangeService getRate display
In the current MATLAB directory, find the @CurrencyExchangeService folder. In the folder, you see the following files:
CurrencyExchangeService.m — Contains the M-code for MATLAB object constructor
display.m — Contains the M-code for a generic display method
getRate.m — Contains the M-code for the getRate method
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:
help CurrencyExchangeService/getRate
getRate(obj,country1,country2)
Input:
country1 = (string)
country2 = (string)
Output:
Result = (float)
Call the getRate method to obtain the exchange rate between two countries.
ces = CurrencyExchangeService;
getRate(ces, 'USA', 'France')
ans =
5.1127
getRate(ces, 'Argentina', 'Chile')
ans =
172.3052
To review, the createClassFromWsdl function performs the following actions:
Fetches and parses the WSDL to determine the Web service API
Creates a folder, such as @CurrencyExchangeService, in the current MATLAB directory
Creates the necessary M files in the directory, such as getRate.m, display.m, and CurrencyExchangeService.m, based on the service API
For more information about object-oriented programming in MATLAB, see the MATLAB Programming Fundamentals documentation.
![]() | Product Overview | Building MATLAB Applications with Web Services | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |