C# WCF 和肥皂 1.1

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2229769/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 00:34:27  来源:igfitidea点击:

WCF and Soap 1.1

c#.netwcfweb-servicessoap

提问by Silas Hansen

I am trying to create a service that a 3rd party should hopefully consume.
The consumer is compatible with SOAP 1.1, which is why I am using basicHttpBinding for the server. When the actual request is made, something seems to go wrong with the content types expected by the server. Using basicHttpBinding I dont get why the server still expects 'application/soap+xml' which, to my knowledge, is only required by SOAP 1.2.

I've used wireshark to figure out exactly what those two were communicating about. See tcp stream and setup below.

Any help is appreciated.

我正在尝试创建一个第三方应该希望使用的服务。
消费者与 SOAP 1.1 兼容,这就是我为服务器使用 basicHttpBinding 的原因。发出实际请求时,服务器预期的内容类型似乎出现问题。使用 basicHttpBinding 我不明白为什么服务器仍然需要“application/soap+xml”,据我所知,只有 SOAP 1.2 需要它。

我用过wireshark 来弄清楚这两个人在交流什么。请参阅下面的 tcp 流和设置。

任何帮助表示赞赏。

3rd party app request

第 3 方应用程序请求

POST / HTTP/1.1

SOAPAction: http://tempuri.org/ITestService/Hello

Content-Type: text/xml; charset=utf-8

Host: shdesktop:8000

Content-Length: 297

Expect: 100-continue

Connection: Close

POST / HTTP/1.1

SOAPAction:http: //tempuri.org/ITestService/Hello

内容类型:文本/xml;字符集=utf-8

主机:shdesktop:8000

内容长度:297

期望:100-继续

连接:关闭

WCF Server response

WCF 服务器响应

HTTP/1.1 415 Cannot process the message because the content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8'.

Content-Length: 0

Server: Microsoft-HTTPAPI/2.0

Date: Tue, 09 Feb 2010 14:03:19 GMT

Connection: close

HTTP/1.1 415 无法处理消息,因为内容类型为 'text/xml; charset=utf-8' 不是预期的类型 'application/soap+xml; 字符集=utf-8'。

内容长度:0

服务器:Microsoft-HTTPAPI/2.0

日期:2010 年 2 月 9 日,星期二 14:03:19 GMT

连接:关闭

Service configuration

服务配置

<system.serviceModel>
    <services>
      <service behaviorConfiguration="behTestService" name="ConsoleApplication1.TestService">
        <endpoint address="" binding="mexHttpBinding" contract="IMetadataExchange" />
        <endpoint address="TestService" binding="basicHttpBinding"
            contract="ConsoleApplication1.ITestService" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8000" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="behTestService">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

采纳答案by marc_s

The basicHttpBindingdoes use SOAP 1.1 - but in that case, you would have a content type of application/soap+xml.

basicHttpBinding不使用SOAP 1.1 -但在这种情况下,你将有一个内容类型application/soap+xml

Since your client is sending text/xml- any chance they're expecting a REST interface? This would be handled by the WCF webHttpBinding.

由于您的客户正在发送text/xml- 他们是否有机会期待 REST 接口?这将由 WCF 处理webHttpBinding

Read more about REST in WCF on the MSDN WCF REST Developer Centerand check out the Pluralsight screencast series on WCF REST- highly recommended!

MSDN WCF REST 开发人员中心阅读有关WCF 中 REST 的更多信息,并查看有关 WCF REST的 Pluralsight截屏视频系列- 强烈推荐!

回答by Shiraz Bhaiji

Generally when we get a message / error in a web service which includes the text:

通常,当我们在包含文本的 Web 服务中收到消息/错误时:

content type 'text/xml'

It means that the web server returned an error page instead of the expected xml response.

这意味着 Web 服务器返回了一个错误页面,而不是预期的 xml 响应。

回答by Julian

I had the exact same issue - the definition was saying that it was soap 1.2 but expecting 1.1 as the content-type was different.

我有完全相同的问题 - 定义是说它是肥皂 1.2,但期望 1.1,因为内容类型不同。

I found that if i adjusted my server configuration from:

我发现如果我从以下位置调整我的服务器配置:

...
<endpoint address="" .../>
    <host>
        <baseAddresses>
            <add baseAddress="http://localhost:8001/services/fooService" />
        </baseAddresses>
    </host>
...

To:

到:

...
<endpoint address="fooService" .../>
    <host>
        <baseAddresses>
            <add baseAddress="http://localhost:8001/services" />
        </baseAddresses>
    </host>
...

The wsdl exposed it as Soap 1.1 this time.

这次 wsdl 将其公开为 Soap 1.1。