简体   繁体   English

WCF自定义绑定 - 服务不支持内容类型

[英]WCF custom binding - Content Type not supported by service

I have defined a custom binding in my client and server web.config file, but when I try to connect I get this error, server is running IIS 7 我在我的客户端和服务器web.config文件中定义了自定义绑定,但是当我尝试连接时出现此错误,服务器正在运行IIS 7

Content Type application/xml; 内容类型application / xml; charset=utf-8 was not supported by service http://localhost/contentservice.svc/PairService . 服务http://localhost/contentservice.svc/PairService不支持charset = utf-8。 The client and service bindings may be mismatched. 客户端和服务绑定可能不匹配。

Server: 服务器:

  <system.serviceModel>
  <client>
    <endpoint binding="customBinding"  bindingConfiguration="BinaryBinding" contract="Me.IContentService" name="ContentStagingEndpoint" />
  </client>
  <bindings>
    <customBinding>
      <binding name="BinaryBinding">
        <binaryMessageEncoding/>
        <httpTransport/>
      </binding>
    </customBinding>
  </bindings>
  </system.serviceModel>

Client: 客户:

<system.serviceModel>
  <behaviors>
    <serviceBehaviors>
      <behavior name="ContentService">
        <serviceMetadata httpGetEnabled="true"/>
        <serviceDebug includeExceptionDetailInFaults="true"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <services>
    <service behaviorConfiguration="ContentService" name="Me.ContentService">
      <endpoint address="" binding="customBinding"  bindingConfiguration="BinaryBinding" contract="Contracts.IContentService">
        <identity>
          <dns value="localhost"/>
        </identity>
      </endpoint>
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    </service>
  </services>
  <bindings>
    <customBinding>
      <binding name="BinaryBinding">
        <binaryMessageEncoding/>
        <httpTransport/>
      </binding>
    </customBinding>
  </bindings>
</system.serviceModel>

and here is the code that initiates the call: 这是启动呼叫的代码:

var chan = New WebChannelFactory(Of IContentService)(New Uri("http://localhost/contentservice.svc")).CreateChannel();

chan.PairService();

找到解决方案后,我不得不使用ChannelFactory而不是WebChannelFactory

var proxy =  ChannelFactory(Of IContentService).CreateChannel(New EndpointAddress("http://localhost/service.svc"))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM