Using Web Services in MATLAB Applications

Getting Started

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.

Building a Simple Web Service

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:

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

  2. In XMethods Demo Services, click the Currency Exchange Rate link near the bottom of the page.

  3. 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.

  4. 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
    
  5. In the current MATLAB directory, find the @CurrencyExchangeService folder. In the folder, you see the following files:

    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)
    
  6. 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:

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

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS