2011-06-25 40 views
2

我需要通过WCF服务传递超过64kb的数据。要做到这一点我已经配置了服务器端(托管WCF服务)的方式如下:通过WCF服务传输大量数据(超过64kb)

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

当我打电话要求的方法我已收到以下错误:

Content Type application/soap+xml; charset=utf-8 was not supported by service http://localhost:82/MyService.svc . The client and service bindings may be mismatched.

请指教,什么是我的绑定不匹配?

谢谢。

回答

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终结元数据交换应该NEVER有任何特殊设置 - 只使用默认mexHttpBinding,不配置任何绑定配置。

+0

事实上,如果您愿意将元数据作为WSDL提供服务,则根本不需要mex端点 - 只需在serviceMetadata行为中设置httpGetEnabled = true(可能还有httpGetUrl,如果您没有基地址) –

0

确保服务器配置文件中的服务名称与服务的完全限定名称匹配 - <system.serviceModel/services/service>元素中的名称属性。如果它不匹配,那么WCF将提供一个默认端点,其绑定为basicHttpBinding(并且它所期望的内容类型与客户端发送的内容类型不同)。

+0

这不是一个案例。谢谢。 – Budda