WCF中的MaxReceivedMessageSize错误

时间:2013-09-17 06:50:44

标签: wcf wcf-data-services wcf-binding wcf-security

作为WCF的新手,请帮助我。我收到了这个错误。我在互联网上搜索了这个问题,我有很多解决方案,但是当我应用这些解决方案时。我面临的一些新问题。所以请为我提供有效的解决方案。

已超出传入邮件的最大邮件大小限额(65536)。要增加配额,请在相应的绑定元素上使用MaxReceivedMessageSize属性。

服务Web.config文件。

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="WSHttpBinding_IService1" maxBufferSize="2147483647"
      maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
        maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    </binding>
  </basicHttpBinding>
</bindings>
<services>
  <service name="WcfServiceZone_Store.Service1" behaviorConfiguration="metadataBehavior">
    <!-- Service Endpoints -->
    <endpoint address="" binding="wsHttpBinding" contract="WcfServiceZone_Store.IService1">
      <identity>
        <dns value="localhost"/>
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="metadataBehavior">
      <!-- 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="false"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

客户端Web.config文件:

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="WSHttpBinding_IService1" maxBufferSize="2147483647"
      maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
        maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    </binding>
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="http://localhost:50274/Service1.svc" binding="wsHttpBinding" contract="ServiceReference1.IService1">
    <identity>
      <dns value="localhost" />
    </identity>
  </endpoint>
</client>

请告诉我,我需要在哪一方做出改变。

2 个答案:

答案 0 :(得分:3)

您需要在服务器和客户端双方进行更改,但您需要使用相应的绑定 - 您的服务(和客户端)实际使用的绑定!

因此,在您的情况下,在服务器端,该服务已配置为使用wsHttpBinding

<service name="WcfServiceZone_Store.Service1" behaviorConfiguration="metadataBehavior">
   <endpoint address="" binding="wsHttpBinding" contract="WcfServiceZone_Store.IService1">
                                 *************

但是你已经定义了basicHttpBinding .....的较高值,当然不会起作用!

<bindings>
   <basicHttpBinding>
    ****************   this doesn't match with the defined binding on your endpoint!

而且您还没有参考您已定义的新绑定配置 - 您需要告知 WCF才能真正使用这些新的绑定值!

所以你需要在服务器上执行此操作:

<system.serviceModel>
<bindings>
  <wsHttpBinding>
    <binding name="BindingWithMaxSizeIncreased" 
         maxBufferSize="2147483647" maxBufferPoolSize="2147483647" 
         maxReceivedMessageSize="2147483647">
        <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
              maxArrayLength="2147483647" maxBytesPerRead="2147483647" 
              maxNameTableCharCount="2147483647" />
    </binding>
  </wsHttpBinding>
</bindings>

<services>
  <service name="WcfServiceZone_Store.Service1" behaviorConfiguration="metadataBehavior">
    <!-- Service Endpoints -->
    <endpoint 
        address="" 
        binding="wsHttpBinding" 
        bindingConfiguration="BindingWithMaxSizeIncreased"  -- use those new values!
        contract="WcfServiceZone_Store.IService1">
      <identity>
        <dns value="localhost"/>
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
</services>

客户端也是如此:

  • 定义正确绑定的绑定参数(wsHttpBinding - 而不是basicHttpBinding
  • bindingConfiguration的引用添加到<endpoint>,以便实际使用这些值

答案 1 :(得分:0)

对于 customBinding ,使用以下值添加 httpTransport

 <system.serviceModel>
    <bindings>
        <customBinding>
            <binding name="QueryDocumentWSPortBinding">
                <textMessageEncoding messageVersion="Soap12" />

              <httpTransport manualAddressing="false" maxBufferPoolSize="524288"
                            maxReceivedMessageSize="2147483647" allowCookies="false" authenticationScheme="Anonymous"
                            bypassProxyOnLocal="false" decompressionEnabled="true" hostNameComparisonMode="StrongWildcard"
                            keepAliveEnabled="true" maxBufferSize="2147483647" proxyAuthenticationScheme="Anonymous"
                            realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false"
                            useDefaultWebProxy="true" />
            </binding>
            ....