WCF SOAP 1.2 服务需要 SOAP 1.1 内容类型 [英] WCF SOAP 1.2 service expecting SOAP 1.1 content type

查看:39
本文介绍了WCF SOAP 1.2 服务需要 SOAP 1.1 内容类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个需要与非 WCF 客户端互操作的 WCF Web 服务(实际上,不会有 WCF 客户端).

I'm building a WCF web service that requires interop with non-WCF clients (in fact, there will be no WCF clients).

我已经使用 SOAP 1.2 编写了一个 WSDL(按照这个例子).我已经验证了 WSDL 并使用了这个文件(不是 WCF 生成的 WSDL,这是表面上的不同)来创建一个 soapUI 测试项目.

I've already written a WSDL using SOAP 1.2 (as per this example). I've validated the WSDL and have used this file (not the WSDL generated by WCF, which is superficially different) to create a soapUI test project.

我要求 Web 服务支持 SOAP 1.2,所以我不能只使用 SOAP 1.1(它在早期原型中运行良好).

I have a requirement that the web service will support SOAP 1.2, so I can't just fall back to SOAP 1.1 (which worked just fine in an early prototype).

我使用了 WSCF.blue 来生成我的 WCF 服务、接口和数据协定类.如果我在浏览器中点击 WCF 服务,一切都可以很好地编译并且端点被公开.世界上似乎一切都很好.

I've used WSCF.blue to generate my WCF service, interface, and data contract classes. Everything compiles nicely and the endpoint is exposed if I hit the WCF service in my browser. All seems well with the world.

当我尝试从soapUi调用一个方法时,我从服务器得到以下响应(从soapUI可见):

When I try to call a method from soapUi I get the following response from the server (as visible from soapUI):

HTTP/1.1 415 Cannot process the message because the content type 
'application/soap+xml;charset=UTF-8;action="http://tempuri.org/FetchMyThing"' 
was not the expected type 'text/xml; charset=utf-8'.
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Mon, 30 Apr 2012 08:15:29 GMT
Content-Length: 0

(为了这个问题的目的,实际的方法名称和命名空间已被手动更改.命名空间中的任何拼写错误都不是我的代码中的错误 - 只是在输入这个问题时的疏忽)

(Actual method names and namespaces have been manually changed for the purposes of this question. Any typos in namespace are not errors in my code - just an oversight in typing up this question)

我知道 SOAP 1.1 指定内容类型必须是 text/xml.SOAP 1.2 需要 application/soap+xml.

I know that SOAP 1.1 specifies that the content type must be text/xml. SOAP 1.2 requires application/soap+xml.

我的原始请求(根据soapUI):

My raw request (as per soapUI):

POST http://localhost/MyWs.svc HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: application/soap+xml;charset=UTF-8;action="http://tempuri.org/FetchMyThing"

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
               xmlns:ns="http://tempuri.org">
   <soap:Header/>
   <soap:Body>
      <ns:fetchMyThingRequest attribute1="1" attribute2="10">
      </ns:fetchMyThingRequest>
   </soap:Body>
</soap:Envelope>

从这个响应中,它告诉我我的请求格式正确 - 这是一个具有正确内容类型的 SOAP 1.2 请求.但是,我的 WCF 服务不期望这种内容类型,我认为这意味着我没有正确配置它并且它仍然认为它是 SOAP 1.1 Web 服务.

From this response, it tells me that my request is properly formed - it's a SOAP 1.2 request with the correct content type. My WCF service, however, does not expect this content type, which I assume means I have not configured it correctly and it still thinks it's a SOAP 1.1 web service.

最小的 Web.config,根据 这篇博文:

Minimal Web.config, as per this blog post:

<system.serviceModel>
  <services>
    <service name="MyNamespace.MyPort">
      <endpoint address="" binding="customBinding" bindingConfiguration="httpSoap12" contract="IWsPort12" />
    </service>
  </services>

  <bindings>
    <customBinding>
      <binding name="httpSoap12">
        <textMessageEncoding messageVersion="Soap12" />
        <httpTransport />
      </binding>
    </customBinding>
  </bindings>
</system.serviceModel>

服务合同的片段:

[ServiceContract(Namespace = "http://tempuri.org")]
public interface IWsPort
{
  [OperationContract(Action = "http://tempuri.org/FetchMyThing")]
  [FaultContract(typeof(WsFault), Action = "http://tempuri.org/FetchMyThing", Name = "fetchMyThingFault")]
  [XmlSerializerFormat(SupportFaults = true)]
  FetchMyThingResponse FetchMyThing(FetchMyThingRequest request);
}

我为我的 WCF 服务启用了服务跟踪,并看到以下异常似乎证实了我的假设:

I enabled service tracing for my WCF service and see the following exception that seems to confirm my hypothesis:

Activity: Listen at 'http://mycomputer/MyWs.svc
<Exception>
  <ExceptionType>System.ServiceModel.ProtocolException, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</ExceptionType>
  <Message>Content Type application/soap+xml;charset=UTF-8;action="http://tempuri.org/FetchMyThing" was sent to a service expecting text/xml; charset=utf-8.  The client and service bindings may be mismatched.   
  </Message>
(erroneous detail snipped)
</Exception>

因此,我的合同和服务绑定可能不匹配,如果可以相信此消息,但根据我对 WCF 的理解,我的配置(或至少其背后的意图)是正确的.

So, my contract and service bindings are probably mismatched, if this message is to believed, but from what I understand of WCF my configuration (or at least the intent behind it) is correct.

有人知道我的配置有什么问题吗?

Does anyone have any ideas as to what's wrong with my configuration?

推荐答案

我唯一能想到的就是因为您没有详细指定绑定,并且它使用 HTTP(按照这个:"在 'http://mycomputer/MyWs.svc' 中收听,然后使用默认值(即 basicHttpBinding) 为此,这是造成不匹配?

The only thing I can think with it is that because you've not specified a binding in a lot of detail, and its using HTTP (as per this: "Listen at 'http://mycomputer/MyWs.svc'") then is it using the default (i.e. basicHttpBinding) for this, which is creating the mismatch?

这篇关于WCF SOAP 1.2 服务需要 SOAP 1.1 内容类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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