【问题标题】:Transferring big amount of data (more than 64kb) through the WCF service通过 WCF 服务传输大量数据(超过 64kb)
【发布时间】:2011-09-22 10:16:42
【问题描述】:

我需要通过 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>

当我调用所需的方法时,我收到以下错误:

内容类型 application/soap+xml;服务 http://localhost:82/MyService.svc 不支持 charset=utf-8。客户端和服务绑定可能不匹配。

请指教,我的绑定有什么不匹配的地方?

谢谢。

【问题讨论】:

    标签: wcf wcf-binding


    【解决方案1】:

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

    【讨论】:

      【解决方案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 并且不要为此配置任何绑定配置。

      【讨论】:

      • 事实上,如果您愿意将元数据作为 WSDL 提供,那么您根本不需要 mex 端点 - 只需设置 httpGetEnabled = true (如果您没有基地址,也可能设置 httpGetUrl ) 关于服务元数据行为
      猜你喜欢
      • 2012-04-29
      • 2012-02-24
      • 2011-11-04
      • 2012-02-11
      • 2012-01-03
      • 2012-11-22
      • 1970-01-01
      • 1970-01-01
      • 2018-03-06
      相关资源
      最近更新 更多