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.
---> 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.
The correct code looks like this:
The particular differences are:
I have added an example of the
parseSoapResponsecall 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,parseSoapResponsereturned 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:to get the XML in a java string and then:
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.
I still do not know how to view the outgoing and incoming HTTP traffic in MATLAB like you can in a browser.