使用Matlab发送SOAP请求

时间:2012-06-27 06:57:12

标签: xml web-services matlab soap webservices-client

我在发送Matlab SOAP请求时遇到了麻烦 callSoapService(endpoint,soapAction,message)< --http://www.mathworks.com/help/techdoc/ref/callsoapservice.html

例如,如何在http://www.webservicex.net/FedWire.asmx?WSDL

中找到端点,soapAction和消息

我知道wsdl中有多个可能的soapActions,端点和消息,但我只是在寻找任何SOAP请求的示例。

1 个答案:

答案 0 :(得分:2)

这是您需要完成的过程。

首先,从WDSL定义创建一个类:

url = 'http://www.webservicex.net/FedWire.asmx?WSDL';
className = createClassFromWsdl(url);

这将在当前目录中创建一个名为@FedWire的目录。您可以在此目录中输入或使用以下内容来探索FedWire提供的服务:

methods(FedWire)

在使用Web服务之前,请创建FedWire对象的实例:

fw = FedWire;
classType = class(fw) % to confirm the class type.

使用服务,例如GetParticipantByLocation,它需要City和StateCode:

 [Result, FedWireLists] = GetParticipantsByLocation(fw, 'New York', 'NY')

结果应为true,FedWireLists是一个包含返回数据的深度嵌套结构。

打开@FedWire \ GetParticipantsByLocation.m揭示了MATLAB生成的代码如何使用createSoapMessage和callSoapService。如果服务不支持WSDL查询,则必须使用这些低级函数。

createSoapMessage的参数填充如下:

  • NAMESPACE:' http://www.webservicex.net/'
  • 方法:' GetParticipantsByLocation'
  • 价值观:{'纽约',' NY'}
  • NAMES:{' City',' StateCode'}
  • TYPES:{' {http://www.w3.org/2001/XMLSchema} string',' {http://www.w3.org/2001/XMLSchema} string& #39;}
  • STYLE:'文件'

和callSoapService:

  • 终点:' http://www.webservicex.net/FedWire.asmx'
  • SOAPACTION:' http://www.webservicex.net/GetParticipantsByLocation'
  • MESSAGE:createSoapMessage调用的结果。

以下代码使用低级别调用进行相同的查询:

% createSoapMessage(NAMESPACE,METHOD,VALUES,NAMES,TYPES,STYLE) creates a SOAP message.
soapMessage = createSoapMessage( ...
  'http://www.webservicex.net/', ...
  'GetParticipantsByLocation', ...
  {'New York', 'NY'}, ...
  {'City', 'StateCode'}, ...
  {'{http://www.w3.org/2001/XMLSchema}string', ...
   '{http://www.w3.org/2001/XMLSchema}string'}, ...
  'document')

% callSoapService(ENDPOINT,SOAPACTION,MESSAGE) sends the MESSAGE,
response = callSoapService( ...
    'http://www.webservicex.net/FedWire.asmx', ...
    'http://www.webservicex.net/GetParticipantsByLocation', ...
    soapMessage);

%parseSoapResponse Convert the response from a SOAP server into MATLAB types.
[result, participants] = parseSoapResponse(response)  

我在使这些示例工作时遇到了很多麻烦,因为我正在利用我从其示例XML中获取的www.webserviceX.NET这样的服务域名。当我改为小写时,它起作用了。

使用createClassFromWsdl的示例是对...的改编  http://www.mathworks.co.uk/products/bioinfo/examples.html?file=/products/demos/shipping/bioinfo/connectkeggdemo.html

相关问题