WCF 中的 MaxReceivedMessageSize 错误

viv*_*ain 5 wcf wcf-binding wcf-security wcf-data-services

由于我是 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>
Run Code Online (Sandbox Code Playgroud)

客户端 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>
Run Code Online (Sandbox Code Playgroud)

请告诉我,我需要在哪一边进行更改。

mar*_*c_s 4

您需要在双方(服务器和客户端)上进行更改,但您需要将其更改为适当的绑定 - 您的服务(和客户端)实际使用的绑定!

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

<service name="WcfServiceZone_Store.Service1" behaviorConfiguration="metadataBehavior">
   <endpoint address="" binding="wsHttpBinding" contract="WcfServiceZone_Store.IService1">
                                 *************
Run Code Online (Sandbox Code Playgroud)

但是您已经在...上定义了更高的值basicHttpBinding,当然这是行不通的!

<bindings>
   <basicHttpBinding>
    ****************   this doesn't match with the defined binding on your endpoint!
Run Code Online (Sandbox Code Playgroud)

而且您也没有引用您定义的新绑定配置 - 您需要告诉WCF 实际使用这些新绑定值!

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

<system.serviceModel>
<bindings>
  <wsHttpBinding>
    <binding name="BindingWithMaxSizeIncreased" 
         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>
Run Code Online (Sandbox Code Playgroud)

在客户端也是如此:

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