传入消息的最大消息大小配额(65536)已被超过。

7
我的WCF服务有一个OperationContract,它接受一个对象数组作为参数。这可能会非常大。在寻找Bad Request: 400的解决方法时,我发现了真正的原因:最大消息大小。
我知道这个问题以前已经被问过很多次了。我尝试了每个人都说的:“增加客户端和服务器配置文件中的大小。”我已经这样做了。但它仍然不起作用。
我的服务的web.config:
<system.serviceModel>
    <services>
      <service name="myService">
        <endpoint name="myEndpoint" address=""
                  binding="basicHttpBinding"
                  bindingConfiguration="myBinding"
                  contract="Meisel.WCF.PDFDocs.IPDFDocsService" />
      </service>
    </services>
    <bindings>
      <basicHttpBinding>
        <binding name="myBinding"
                 closeTimeout="00:11:00"
                 openTimeout="00:11:00"
                 receiveTimeout="00:15:00"
                 sendTimeout="00:15:00"
                 maxBufferSize="2147483647"
                 maxReceivedMessageSize="2147483647"
                 maxBufferPoolSize="2147483647"
                 transferMode="Buffered"
                 allowCookies="false"
                 bypassProxyOnLocal="false"
                 hostNameComparisonMode="StrongWildcard"
                 messageEncoding="Text"
                 textEncoding="utf-8"
                 useDefaultWebProxy="true">
          <readerQuotas maxDepth="2147483647"
                        maxStringContentLength="2147483647"
                        maxArrayLength="2147483647"
                        maxBytesPerRead="2147483647"
                        maxNameTableCharCount="2147483647" />
          <security mode="None" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

我的客户的 app.config 文件:

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IPDFDocsService"
                 closeTimeout="00:11:00"
                 openTimeout="00:11:00"
                 receiveTimeout="00:10:00"
                 sendTimeout="00:11:00"
                 allowCookies="false"
                 bypassProxyOnLocal="false"
                 hostNameComparisonMode="StrongWildcard"
                 maxBufferSize="2147483647"
                 maxBufferPoolSize="2147483647"
                 maxReceivedMessageSize="2147483647"
                 messageEncoding="Text"
                 textEncoding="utf-8"
                 transferMode="Buffered"
                 useDefaultWebProxy="true">
          <readerQuotas maxDepth="32"
                        maxStringContentLength="2147483647"
                        maxArrayLength="2147483647"
                        maxBytesPerRead="2147483647"
                        maxNameTableCharCount="2147483647" />
          <security mode="None">
            <transport clientCredentialType="None"
                       proxyCredentialType="None"
                       realm="" />
            <message clientCredentialType="UserName"
                     algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:8451/PDFDocsService.svc"
                behaviorConfiguration="MoreItemsInObjectGraph"
                binding="basicHttpBinding"
                bindingConfiguration="BasicHttpBinding_IPDFDocsService"
                contract="PDFDocsService.IPDFDocsService"
                name="BasicHttpBinding_IPDFDocsService" />
    </client>
    <behaviors>
      <endpointBehaviors>
        <behavior name="MoreItemsInObjectGraph">
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>

我可能错过了什么或做错了什么?就好像服务忽略了我在maxReceivedBufferSize中输入的内容。

提前致谢, Kyle

更新

这里有两个StackOverflow问题,它们也没有收到答案:

https://stackoverflow.com/questions/2880623/maxreceivedmessagesize-adjusted-but-still-getting-the-quotaexceedexception-with

WCF MaxReceivedMessageSize属性不起作用


乍一看似乎没问题。你在代码中配置了终端点吗?如果是这样的话,可能会覆盖配置设置。 - Jeff Schumacher
你是如何托管服务的?IIS吗? - Simon Chadwick
@Jeff:我只是创建了一个新的服务客户端实例,然后调用操作契约,将我的自定义类作为参数传递进去。没有什么花哨的东西。@Simon:我正在使用ASP .NET开发服务器。目前,它都是本地的。 - DaleyKD
2个回答

7
在服务配置文件中,元素缺少“name”属性。
<behaviors>
  <serviceBehaviors>
    <behavior name="StackOverflow">

在服务元素中应该有对此名称的引用:

<system.serviceModel>
    <services>
        <service behaviorConfiguration="StackOverflow" name="myService">
            <endpoint address="" binding="basicHttpBinding" bindingConfiguration="myBinding"

一般来说,使用Visual Studio“工具”菜单中调用的“WCF服务配置编辑器”对WCF配置文件进行验证和修改是一个不错的主意。

另外,对于该服务未定义终结点行为,我不确定这是否有影响。


如果我告诉你,当我给我的行为添加一个名称时,WCFTestClient会给我返回错误消息:“错误:无法获取元数据。元数据包含无法解析的引用。服务不支持内容类型application/soap+xml; charset=utf-8。客户端和服务绑定可能不匹配。远程服务器返回了一个错误:(415) 不支持的媒体类型.HTTP GET。HTML文档不包含Web服务发现信息。” 这就是为什么我没有为我的行为添加名称的原因。 - DaleyKD
我仍然不确定这个问题的真正解决方案是什么,但我已经成功解决了我的原始问题,使得这个问题无关紧要。顺便说一下,似乎我通过确保我的服务使用behaviorConfiguration来摆脱了上述错误。谢谢! - DaleyKD

0

我曾经遇到过与WCF测试相同的问题,而且我已经正确设置了配置文件。如果您的配置文件没有任何问题,我建议尝试使用另一个程序(例如SOAP UI)来测试服务。我认为这个错误不是来自服务,而是来自WCF测试。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接