在这个特定的MATLAB示例中使用SOAP的方式有什么问题? [英] What is wrong with the way I am using SOAP in this specic MATLAB example?

查看:108
本文介绍了在这个特定的MATLAB示例中使用SOAP的方式有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 http://www.webservicex.net/ 连接到一个示例肥皂服务器使用以下MATLAB代码:

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>

我知道服务器正在响应。我可以用Python询问它,并且这样的泡沫如下:

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?

我还想知道如何查看createSoapMessage创建的DOM对象以及如何查看MATLAB发送和接收的xml。

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.

推荐答案

正确的代码如下所示:

% 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)  

具体的区别是:


  • STYLE参数是'document',而不是'rpc'

  • www.webservicex.net在他们如何大小写,重要!

  • 端点参数结束.asmx,不包括WDSL。

我也添加了一个 parseSoapResponse 调用的例子。这也给我带来了麻烦。对于此Web服务,此调用只返回包含请求的数据的结构。当在同一个主机上使用不同的服务时, parseSoapResponse 返回两个输出,一个好/坏的结果和数据。请参阅使用Matlab发送SOAP请求

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.

最后,在回答我关于查看诸如消息的中间XML的补充问题时,MATLAB中的soap消息使用以下内容:

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())

获取XML字符串中的XML,然后:

to get the XML in a java string and then:

 matlabString = char(javaString)

在matlab字符串中获取XML。

to get the XML in a matlab string.

以下代码添加了换行符和空格以在多行中显示XML以帮助调试。

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')

我仍然不知道如何在浏览器中查看MATLAB中的传出和传入HTTP流量。

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

这篇关于在这个特定的MATLAB示例中使用SOAP的方式有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆