c# - WCF - 通过 HTTP 抛出客户端和服务绑定(bind)不匹配异常的二进制编码

标签 c# wcf

异常:

Content Type application/soap+msbin1 was not supported by service http://localhost:1500/MyService.svc. The client and service bindings may be mismatched.

客户端配置:

  <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>

最佳答案

如果没有 customBindings,您将无法使用 binaryMessageEncodingHTTP。您可以开箱即用地使用 textMessageEncodingmtomMessageEncoding

请参阅此博客文章 reference on using customBindings with HTTP transport .

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

关于c# - WCF - 通过 HTTP 抛出客户端和服务绑定(bind)不匹配异常的二进制编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4904097/

相关文章:

c# - 如何在同一站点的 ashx 和 aspx 文件中使用 await/async?

c# - 如何对整数字符串进行排序?

c# - 如何在 WCF 服务中使用 CefSharp?

c# - 未调用 WCF 服务回调

c# - 使用 IIS 与第三方 dll 的 WCF 服务连接

c# - 谁能告诉我为什么在 LINQ 中会发生这种情况?

c# - '/' 应用程序中的服务器错误。系统.Web.Http.WebHost

wcf - 如何查看为 wcf 函数生成的 WSDL

c# - WCF 自定义验证器 : How to initialize a "User" object from custom validator

c# - EF有时可以在成功写入后重试吗?