1

I am trying to connect to an example soap server at http://www.webservicex.net/ using the following MATLAB code:

% createSoapMessage(NAMESPACE,METHOD,VALUES,NAMES,TYPES,STYLE) creates a SOAP message.
% VALUES, NAMES, and TYPES are cell arrays.  
m = createSoapMessage('http://www.webserviceX.NET', 'GetCitiesByCountry', ...
  {'Australia'}, {'CountryName'}, { '{http://www.w3.org/2001/XMLSchema}string' }, 'rpc')

%    callSoapService(ENDPOINT,SOAPACTION,MESSAGE) sends the MESSAGE,
%    a Java DOM, to the SOAPACTION service at the ENDPOINT.
response = callSoapService('http://www.webservicex.net/globalweather.asmx?WSDL', ...
  'http://www.webserviceX.NET/GetCitiesByCountry', m);

I get the following response (with line endings inserted for viewing):

val =
  <?xml version="1.0" encoding="utf-8"?>
  <soap:Envelope
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
      <soap:Fault>
        <faultcode>soap:Server</faultcode>
          <faultstring>System.Web.Services.Protocols.SoapException: 
          Server was unable to process request. 
          ---&gt; System.Data.SqlClient.SqlException: 
          Procedure or function 'getWCity' expects parameter '@CountryName',
          which was not supplied.
          at WebServicex.GlobalWeather.GetCitiesByCountry(String CountryName)
          --- End of inner exception stack trace ---
        </faultstring><detail />
      </soap:Fault>
    </soap:Body>
  </soap:Envelope>

I know that the server is responding. I can interrogate it with Python and suds like this:

from suds.client import Client
url = 'http://www.webservicex.net/globalweather.asmx?WSDL'
client = Client(url)
result = client.service.GetCitiesByCountry('Australia')

My simple question is what am I doing wrong?

I would also like to know how to view the DOM object that createSoapMessage creates and how to view the xml that MATLAB sends and receives.

Nigel Davies
  • 1,640
  • 1
  • 13
  • 26
  • I have partly answered this question here: http://stackoverflow.com/questions/11220900/sending-soap-request-with-matlab. – Nigel Davies Aug 14 '12 at 16:09

1 Answers1

1

The correct code looks like this:

% createSoapMessage(NAMESPACE,METHOD,VALUES,NAMES,TYPES,STYLE) creates a SOAP message.
message = createSoapMessage( ...
  'http://www.webserviceX.NET', ...
  'GetCitiesByCountry', ...
  {'Australia'}, ...
  {'CountryName'}, ...
  {'{http://www.w3.org/2001/XMLSchema}string' }, ...
  'document')

% callSoapService(ENDPOINT,SOAPACTION,MESSAGE) sends the MESSAGE,
response = callSoapService( ...
  'http://www.webservicex.net/GlobalWeather.asmx', ...
  'http://www.webserviceX.NET/GetCitiesByCountry', ...
  message);

% parseSoapResponse Convert the response from a SOAP server into MATLAB types.
cities = parseSoapResponse(response)  

The particular differences are:

  • The STYLE parameter is 'document', not 'rpc'
  • www.webservicex.net is very inconsistent in how they capitalize, and it matters!
  • The endpoint parameter ends .asmx and does not inclcude ?WDSL.

I have added an example of the parseSoapResponse call too. This also caused me trouble. For this web service, this call returns just the structure containing the requested data. When working with a different service on the same host, parseSoapResponse returned two outputs, a good/bad result and the data. See sending SOAP request with Matlab.

Finally, in answer to my supplementary question about viewing the intermediate XML such as message, the soap message, in MATLAB, use the following:

 javaString = message.saveXML(message.getFirstChild())

to get the XML in a java string and then:

 matlabString = char(javaString)

to get the XML in a matlab string.

The following code adds newlines and spaces to display the XML over several lines to help debugging.

ms2 = regexprep(matlabString ,'>','>\n')
ms3 = regexprep(ms2,' x','\n  x')

I still do not know how to view the outgoing and incoming HTTP traffic in MATLAB like you can in a browser.

Community
  • 1
  • 1
Nigel Davies
  • 1,640
  • 1
  • 13
  • 26