【问题标题】:WCF - Binary Encoding over HTTP throwing client and service binding mismatch exceptionWCF - 通过 HTTP 的二进制编码引发客户端和服务绑定不匹配异常
【发布时间】:2011-02-04 23:59:15
【问题描述】:

例外:

内容类型 application/soap+msbin1 服务不支持 http://localhost:1500/MyService.svc。 客户端和服务绑定可能是 不匹配。

客户端配置:

  <system.serviceModel>
    <bindings>

    <customBinding>
        <binding name="NetHttpBinding" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00">
          <binaryMessageEncoding />
          <httpTransport allowCookies="false" bypassProxyOnLocal="false"
                         hostNameComparisonMode="StrongWildcard" maxBufferSize="65536"
                         maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                         transferMode="Buffered" useDefaultWebProxy="true" />
        </binding>
      </customBinding>

    </bindings>
    <client>
      <endpoint address="http://localhost:1500/MyService.svc"
        binding="customBinding" bindingConfiguration="NetHttpBinding"
        contract="APP.BLL.IMyServiceContract" name="MyServiceEndpoint" />
    </client>
  </system.serviceModel>

服务器配置:

  <system.serviceModel>
    <bindings>
      <customBinding>
        <binding name="NetHttpBinding" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00">
          <binaryMessageEncoding />
          <httpTransport allowCookies="false" bypassProxyOnLocal="false"
                         hostNameComparisonMode="StrongWildcard" maxBufferSize="65536"
                         maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                         transferMode="Buffered" useDefaultWebProxy="true" />
        </binding>
      </customBinding>
    </bindings>

    <services>
      <service name="MyAppService">
        <endpoint address="" binding="customBinding" bindingConfiguration="NetHttpBinding"
                  contract="APP.BLL.IMyServiceContract">
        </endpoint>
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

  </system.serviceModel>

【问题讨论】:

  • 服务是否托管在 IIS 或其他托管应用程序中?
  • 我现在一直在 Visual Studio 中托管它。内置的网络服务器(我永远记不起它的名字)。完成后我会将其部署到 IIS。
  • 如果服务器 endpoint Contract 与端点使用的实际合同不匹配,我也会遇到同样的问题。

标签: c# wcf


【解决方案1】:

您不能在没有 customBindings 的情况下使用 binaryMessageEncoding 和 HTTP。您可以直接使用 textMessageEncoding 或 mtomMessageEncoding。

请参阅此博客文章以获取 reference on using customBindings with HTTP transport。

<bindings>
    <customBinding>
      <binding name="basicHttpBinaryBinding">
        <binaryMessageEncoding />             
        <httpTransport />
      </binding>
    </customBinding>
</bindings>

【讨论】:

  • 这与我在某些网站上看到的内容相矛盾:jeffbarnes.net/blog/post/2007/02/22/…你有文章讨论这个吗?
  • HTTP 是基于文本的协议。 MTOM 专门设计用于向 HTTP 添加二进制附件(旧的 DIME 协议)。二进制编码器需要二进制流而不是文本流。
  • @mbursill - 我更新了答案以反映经过测试的功能。您可以使用 customBinding 配置获取 application/soap+msbin1 内容类型。 Jeff Barnes posting 是准确的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-24
  • 2012-02-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多