【问题标题】:WCF WS throwing MaxReceivedMessageSizeExceededWCF WS 抛出 MaxReceivedMessageSizeExceeded
【发布时间】:2011-03-17 18:06:33
【问题描述】:

我有一个 WCF Web 服务,它接受一些自定义对象和一些作为字节数组发送的文档。

但是每次我发送一个文档(不是特别大的文档)时,WS 都会返回一个 400 错误请求,并且在跟踪日志中它似乎抛出了一个 MaxReceivedMessageSizeExceeded。 说

System.ServiceModel.ProtocolException: 最大邮件大小配额 传入消息 (65536) 已 超过。要增加配额,请使用 MaxReceivedMessageSize 属性 适当的绑定元素。

现在客户端应用在其app.config 中有这个

<wsHttpBinding>
    <binding name="WSHttpBinding_IReferrals" 
        closeTimeout="00:01:00" openTimeout="00:01:00" 
        receiveTimeout="00:10:00" sendTimeout="00:01:00"
        bypassProxyOnLocal="false" transactionFlow="false" 
        hostNameComparisonMode="StrongWildcard"
        maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" 
        messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
        allowCookies="false">
        <readerQuotas maxDepth="32" 
            maxStringContentLength="8192" maxArrayLength="16384"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />

在 WCF web.config 我有这个

<service behaviorConfiguration="WCFReferrals.Service1Behavior"
        name="WCFReferrals.Referrals">
     <endpoint address="" binding="wsHttpBinding" contract="WCFReferrals.IReferrals">
          <identity>
            <dns value="localhost" />
          </identity>
     </endpoint>
     <endpoint address="mex" binding="wsHttpBinding" contract="IMetadataExchange" />
 </service>
 ....
 <binding name="wsHttpBinding" maxBufferPoolSize="2147483647"
          maxReceivedMessageSize="2147483647">
     <readerQuotas maxDepth="32" maxStringContentLength="2147483647"
            maxArrayLength="2147483647" maxBytesPerRead="4096" 
            maxNameTableCharCount="16384" />
 </binding>

据我所知,显然我遗漏了一些东西

任何帮助都会很乐意接受

谢谢

自然

【问题讨论】:

    标签: .net wcf


    【解决方案1】:

    首先:在您的服务器端,您定义具有较大消息大小的绑定配置,但您不从端点引用它。

    <service behaviorConfiguration="WCFReferrals.Service1Behavior"
             name="WCFReferrals.Referrals">
       <endpoint 
             address="" 
             binding="wsHttpBinding" 
             bindingConfiguration="LargeSizeMessages"  <== you need to reference the binding config (by specifying its name
            contract="WCFReferrals.IReferrals">
        </endpoint>
        .....
      </service>
      ....
      <binding name="LargeSizeMessages"   <== give it a meaningful name
           maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
           <readerQuotas maxDepth="32" maxStringContentLength="2147483647"
               maxArrayLength="2147483647" maxBytesPerRead="4096" 
               maxNameTableCharCount="16384" />
      </binding>
    

    另外:你在客户端做同样的事情吗?您的客户端配置(app.configweb.config)是否还包括大消息大小的绑定配置?您是否在您的&lt;client&gt; .. &lt;endpoint&gt; 元素中引用该绑定配置??

    【讨论】:

    • 我对这个完全陌生,这很奏效。我想我在想绑定属性指向你想要的绑定。不是绑定配置。非常感谢。
    • @nat:单个绑定可以有任意数量的绑定配置 - 这就是为什么您需要通过名称引用您想要的端点的配置
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-21
    • 2011-07-17
    • 1970-01-01
    • 2018-07-11
    • 1970-01-01
    • 1970-01-01
    • 2014-04-14
    相关资源
    最近更新 更多