Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WCF-HTTP上的二进制编码引发客户端和服务绑定不匹配异常_C#_Wcf - Fatal编程技术网

C# WCF-HTTP上的二进制编码引发客户端和服务绑定不匹配异常

C# WCF-HTTP上的二进制编码引发客户端和服务绑定不匹配异常,c#,wcf,C#,Wcf,例外情况: 内容类型应用程序/soap+msbin1 服务不支持 . 客户端和服务绑定可能是 不匹配 客户端配置: <system.serviceModel> <bindings> <customBinding> <binding name="NetHttpBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout

例外情况:

内容类型应用程序/soap+msbin1 服务不支持 . 客户端和服务绑定可能是 不匹配

客户端配置:

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

服务器配置:

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


如果没有自定义绑定,则无法使用二进制消息编码HTTP。您可以使用开箱即用的textMessageEncodingmtomessageencoding

有关详细信息,请参阅此博客文章



该服务是托管在IIS还是其他托管应用程序中?我已经在Visual Studio中托管了一段时间了。内置的Web服务器(我永远记不起它的名字)。我将在完成后将其部署到IIS。如果服务器与端点使用的实际契约不匹配,我也会遇到同样的问题。这与我在某些网站上读到的内容相矛盾:您是否有一篇文章讨论过这一点?HTTP是一种基于文本的协议。MTOM是专门为向HTTP添加二进制附件(旧的DIME协议)而设计的。二进制编码器需要一个二进制流而不是文本流。@mbursill-I更新了答案以反映测试的功能。您可以使用
customBinding
配置获取
application/soap+msbin1
内容类型。这是准确的。