如何获取消息合同以在正文中发送soap动作而不是标题

时间:2011-03-29 16:34:30

标签: .net wcf web-services soap

当我在我的svcutil命令中使用“/ messageContract”时,我的soap消息会在soap信封的标题中发送操作或操作,而不是正文。远程端点是供应商基于Java的服务,我无法控制。

我需要将动作发送到正文中但仍然使用“/ messageContract”。

有谁知道如何实现这一目标?

SOAP信封 WITH “/ messageContract”

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">GetCapabilities</Action>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"></s:Body>
</s:Envelope>

SOAP信封没有“/ messageContract”

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header></s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<GetCapabilities xmlns="http://www.opengis.net/cat/csw/2.0.2"></GetCapabilities>
</s:Body>
</s:Envelope>

我的svcutil命令:

svcutil /target:code http://localhost/sarpilot/xml/mywisdl.wsdl /messageContract /out:WebService.cs /config:WebService.config

1 个答案:

答案 0 :(得分:3)

确实您的目标(基于Java)Web服务需要SOAP主体中的基于Microsoft的命名空间元素而不是SOAP标头吗?这对我来说似乎是假的。

<Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">GetCapabilities</Action>

大多数Web服务只需要Action in the HTTP header,而不是SOAP正文的一部分:

POST /StockQuote HTTP/1.1
Content-Type: text/xml; charset="utf-8"
Content-Length: nnnn
SOAPAction: "http://electrocommerce.org/abc#MyMessage"

<SOAP-ENV:Envelope...

您是否可以提供原始的,有效的SOAP请求(包括HTTP标头)以进行比较?您可以使用这个基于Web页面的小客户端Simplest SOAP example using Javascript独立于.NET进行测试。我假设你的其他帖子here显示了一个“工作”请求,你实际上不需要SOAP主体中的Microsoft Action元素。