Documentation Center

  • Trial Software
  • Product Updates

Access Web Services Using MATLAB SOAP Functions

Using the MATLAB SOAP Functions

To use the createSoapMessage, callSoapService, and parseSoapResponse functions, you need some knowledge of SOAP as well as specific information about the Web services you want to use, such as the endpoint and the operations. If the server provides a WSDL document, see Access Web Services That Use WSDL Documents for a potentially more convenient option.

This is a typical way to use the SOAP functions. For details about each function, see the function reference page.

  1. Construct a message you want to send to the server using createSoapMessage. Provide this input to the function: namespace of the server, name of the server operations you want to run, input you need to provide for that operations, parameter of the operation, data types, and message style (optional).

  2. Send the message to the server using callSoapService. Provide this input to the function: endpoint, SOAP action, and the SOAP message you created in step 1. MATLAB® returns the reply from the server.

  3. Convert the reply from the server and extract the desired data into a MATLAB variable using parseSoapResponse. MATLAB automatically converts SOAP data types to MATLAB data types—for more information, see XML-MATLAB Data Type Conversion Used in Web Services.

Example — SOAP Functions

This example retrieves information about books from a library database, specifically, the author's name for a given book title.

    Note:   The example does not use an actual endpoint; therefore, you cannot run it. The example only illustrates how to use the SOAP functions.

  1. Create a SOAP message that retrieves the name of the author of a book titled "In the Fall":

    message = createSoapMessage(...
    'urn:LibraryCatalog',... % Relative path to namespace of library service on local intranet
    'getAuthor',... % Method (operation) provided by service to retrieve author's name
    {'In the Fall'},... % Input that method requires; here, the title of the book
    {'nameToLookUp'},... % Name of paremeter of getAuthor
    {'{http://www.w3.org/2001/XMLSchema}string'},... % Data type for the result
    'rpc') % SOAP message style

    MATLAB returns

    message =
     
    [#document: null]

    This response does not necessarily indicate that the message is valid, although certain input problems produce an error message.

  2. Send the message to the server for processing, and get the result (author's name) back from the server in a SOAP message:

    response = callSoapService('http://test/soap/services/LibraryCatalog',... % Service's endpoint
    'urn:LibraryCatalog#getAuthor',... % Server method to run
    message) % SOAP message created using createSoapMessage

    MATLAB returns the following SOAP message in one long line (displayed here in separate lines for legibility):

    <?xml version="1.0" encoding="utf-8"?>
    <soapenv:Envelope 
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Body>
    <getAuthorResponse xmlns="urn:LibraryCatalog">
    <ns1:getAuthorReturn xmlns:ns1="http://latestversion.soap.test">
    Kate Alvin
    </ns1:getAuthorReturn>
    </getAuthorResponse>
    </soapenv:Body>
    </soapenv:Envelope>
  3. Extract the author's name from the SOAP message returned by the server in step 2:

    author = parseSoapResponse(response)

    MATLAB returns:

    author = Kate Alvin

    In MATLAB, author is a char class. MATLAB automatically converted the XML string data type to char.

Was this topic helpful?