Products & Services Industries Academia Support User Community Company

Learn more about MATLAB   

Accessing Web Services That Use WSDL Documents

Using the createClassFromWsdl Function

A WSDL document uses a standard format to describe a server's operations, arguments, and transactions. The createClassFromWsdl function creates a MATLAB class that allows you to use the server APIs.

To use the createClassFromWsdl function, you need to know the location of the Web service's WSDL document. The createClassFromWsdl function works with WSDL documents that comply with the WS-I 1.0 standard and use one of these forms: RPC-encoded, RPC-literal, Document-literal, or Document-literal-wrapped.

If the Web service does not provide a WSDL document, see Accessing Web Services Using MATLAB SOAP Functions for an alternative.

Here are the basic steps for using the createClassFromWsdl function:

  1. Change the MATLAB current folder to the location where you want to use the files generated from the WSDL document.

  2. Run createClassFromWsdl, supplying the WSDL document location, which can be a URL or a path to a file.

    The function converts the server's APIs to a MATLAB class, and creates a class folder in the current folder. The class folder contains methods for using the server's APIs. The function always creates a constructor method that has the same name as the class, and a display method for the class, called display.

      Note   You only need to run the createClassFromWsdl function once. You can access the class anytime after that.

    For more information, see the createClassFromWsdl reference page

  3. Create an object of the class whenever you want to use the operations of the Web service.

  4. View information about the class to see what methods (operations) are available for you to use.

  5. Use the methods of the object to run applications on and exchange data with the server.

    The methods create SOAP messages and send them to the server. The server performs operations and sends data back to MATLAB.

    MATLAB automatically converts SOAP data types to MATLAB types, and vice versa—for more information, see XML-MATLAB Data Type Conversion Used in Web Services.

Example — createClassFromWsdl Function

This example retrieves information from a database that provides standardized test scores. The WSDL document is located at http://examplestandardtests.com/scoreswebservice?WSDL.

  1. Run the createClassFromWsdl statement:

    createClassFromWsdl('http://examplestandardtests.com/scoreswebservice?WSDL')

    MATLAB creates the class folder @TestScoreWebService in the current folder and displays the name:

    ans = TestScoreWebService

  2. Create an object of the class by running

    obj = TestScoreWebService
    

    MATLAB returns:

    endpoint: 'http://examplestandardtests.com/scoreswebservice'
        wsdl: 'http://examplestandardtests.com/scoreswebservice?WSDL'
    
  3. View the methods of the class to see what you can do. These are two ways to view the methods:

    • Run methods(obj).

    • In the Current Folder browser, view the contents of the @TestScoreWebService folder. The description shows the syntax for the methods.

    For the example, the methods include:

    display
    StudentNames
    Tests
    TestScoreWebService
  4. Use the StudentNames method to retrieve the names of all students who took tests by running

    students = StudentNames(obj)

    MATLAB returns a structure with the names of test takers:

    students = 
    
        StudentInfo: [125x1 struct]
  5. View the data in the first element by running

    students.StudentInfo(1)

    MATLAB returns:

    StudentNameLast: 'Benjamin'
    StudentNameFirst: 'Ali'

    Alternatively, you can view the information using the Variable Editor by running

    openvar(students)

    Then in the Variable Editor, double-click StudentInfo. In the resulting pane, double-click the first <1x1 struct> to view the information. For more information, see Working with Different Types of Data in the Variable Editor.

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

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