1

I am working on understanding how SOAP services work.My client is in Java and the service is using WCF (although in theory this shouldn't matter). If I am given an example of a SOAP envelope and do the following:

-Build a SOAP envelope that exactly follows the example
-Use an HttpPost object to post the data to www.service.com/service.svc

Is this a correct (although improper) way to call the service? Because when I do this, I receive a 400 response, even though my SOAP envelope is the exact same as the example.

4

2 回答 2

0

It should work. You are probably missing some required headers. I suggest to use a TCP monitor, intercept a working request and analize its content.

于 2013-04-28T04:11:41.500 回答
0

我认为您收到 HTTP 400(错误请求)的原因是您的服务正在使用BasicHttpBindingSOAP 1.1,并且您很可能正在发送 SOAP 1.2 消息(正如您在使用 SOAP 1.2 的评论中指出的那样)。两者的消息格式不同。

最简单的解决方案是使用 SOAP 1.1,但如果您必须(或想要)使用 SOAP 1.2,以下可能会有所帮助。

在您的配置文件中,您还没有定义任何端点或绑定 - 这没关系,因为 WCF 将在 4.0 及更高版本中使用默认值。

但是,HTTP 的默认绑定是BasicHttpBinding. 您需要使用支持 SOAP 1.2 的绑定(或将您的消息更改为 SOAP 1.1)。您可以使用WSHttpBinding支持 SOAP 1.2 的 ,但您必须更改安全设置(默认情况下是 Windows)。

另一种选择是使用实现 SOAP1.1 的自定义绑定。

我将举几个例子(我从来没有为 WCF 服务编写过非 .NET 客户端,所以我不能肯定它会起作用,但它至少应该让你朝着正确的方向前进。

WSHttpBinding

通过覆盖配置文件中的协议映射,将HTTP 请求的默认协议映射从 更改为BasicHttpBindingWsHttpBinding

<protocolMapping>
  <addBinding protocol="wsHttpBinding" scheme="http" />
</protocolMapping>

将绑定部分添加到您的配置文件,以便您可以将安全模式设置为无。这属于以下<system.serviceModel>部分:

<bindings>
  <wsHttpBinding>
    <binding>
        <security mode="None" />
    </binding>
  </wsHttpBinding>
</bindings>

请注意,我没有为name绑定上的属性设置值。这会将绑定定义设置为默认值,并结合更改 HTTP 的默认协议以wsHttpBinding使您能够发送 SOAP 1.2。

安全说明*如果您只是想更好地了解 SOAP,将安全设置为 none 很好,但我强烈建议您在生产环境中这样做。

自定义绑定

我从来没有使用过自定义绑定,但是这样的东西应该可以工作:

<bindings>
  <customBinding>
    <binding name="Custom">
      <textMessageEncoding messageVersion="Soap12" />
      <httTransport />
    </binding>
  </customBinding>
</bindings>

您需要将其显式设置为端点(使用端点的bindingConfiguration属性),这意味着您需要在配置文件中创建端点定义。

自定义绑定思想来自带有 BasicHttpBinding 的 SOAP 1.2 消息格式

希望这会给你一些想法,让你重新开始。

于 2013-04-28T18:48:54.377 回答