我需要通过WCF服务传递超过64kb的数据。为此,我已按以下方式配置服务器端(托管WCF服务):
<services>
<service name="MyService" behaviorConfiguration="MyServiceBehavior" >
<endpoint address="" binding="customBinding" contract="MyContract"
bindingName="testBinding" bindingConfiguration="testBinding" />
<endpoint address="mex" binding="customBinding" contract="IMetadataExchange"
bindingName="testBinding" bindingConfiguration="testBinding" />
</service>
</services>
<bindings>
<customBinding>
<binding name="testBinding" >
<textMessageEncoding>
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
</textMessageEncoding>
<httpTransport transferMode="Buffered"
maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647"/>
</binding>
</customBinding>
</bindings>
客户端(消费服务):
<client>
<endpoint address="http://localhost:82/MyService.svc"
binding="customBinding" bindingConfiguration="testBinding"
contract="MyContract"
name="MyName" />
</client>
<bindings>
<customBinding>
<binding name="testBinding" >
<textMessageEncoding>
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
</textMessageEncoding>
<httpTransport transferMode="Buffered"
maxReceivedMessageSize="2147483647"
maxBufferSize="2147483647"/>
</binding>
</customBinding>
</bindings>
当我调用required方法时,我收到了以下错误:
内容类型application / soap + xml;服务http://localhost:82/MyService.svc不支持charset = utf-8。客户端和服务绑定可能不匹配。
请建议,我的绑定中有什么不匹配?
感谢。
答案 0 :(得分:2)
好像你做了太多步骤 - 太复杂了。为什么不使用基于现有绑定的绑定配置?像这样:
<bindings>
<basicHttpBinding>
<binding name="largeBinding"
maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas
maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" maxStringContentLength="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="MyService" behaviorConfiguration="MyServiceBehavior" >
<endpoint
address=""
binding="basicHttpBinding"
bindingConfiguration="largeBinding"
contract="MyContract" />
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
在客户端定义完全相同的绑定配置,并在那里使用它。
此外,用于元数据交换的 MEX端点应从不进行任何特殊设置 - 只需使用默认mexHttpBinding
,不要配置任何绑定配置这一点。
答案 1 :(得分:0)
确保服务器配置文件中的服务名称与服务的完全限定名称匹配 - <system.serviceModel/services/service>
元素中的name属性。如果它不匹配,那么WCF将提供一个默认端点,其绑定是basicHttpBinding(并且它所期望的内容类型与客户端发送的内容类型不同)。