wcf - WCF 中的 MaxReceivedMessageSize 错误

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

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

已超出传入邮件 (65536) 的最大邮件大小配额。要增加配额,请在适当的绑定(bind)元素上使用 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>

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

最佳答案

您需要在双方(服务器和客户端)上进行更改,但您需要将其更改为 合适的绑定(bind) - 您的服务(和客户端)实际使用的绑定(bind)!
因此,在您的情况下,在您的服务器端,该服务配置为使用 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!
而且您也没有引用您定义的新绑定(bind)配置 - 您需要 告诉 WCF 实际使用那些新的绑定(bind)值!
所以你需要在服务器上这样做:
<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>
客户端也一样:
  • 定义绑定(bind)参数正确 绑定(bind)(wsHttpBinding - 不是 basicHttpBinding)
  • 添加对 bindingConfiguration 的引用到<endpoint>以便实际使用这些值
  • 关于wcf - WCF 中的 MaxReceivedMessageSize 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18843079/

    相关文章:

    c# - 如何通过成员(member)/授权在 Azure 上启用 WCF 服务的流传输?

    c# - 在 ServiceModel 客户端配置部分找不到引用契约(Contract)的默认端点元素......................

    wcf - 将 WCF 服务中的数据公开为 oData

    c# - WCF 数据服务 : SaveChanges: An error occurred while processing this request

    c# - Entity Framework - 底层提供程序在 ConnectionString 上失败

    wcf - 使用 REST WCF 数据服务作为 SQL 报告服务的数据源

    asp.net - 使用表单例份验证注销从不同浏览器/计算机登录的用户

    tcp - 无需任何 KeepAlive() 方法的 TCP 持久双工

    c# - 套接字异常 : recvfrom failed: ECONNRESET (Connection reset by peer) occurs

    javascript - 如何将字节数组转换为图像?