【问题标题】:maxReceivedMessageSize on Azure WCF service is too smallAzure WCF 服务上的 maxReceivedMessageSize 太小
【发布时间】:2011-06-17 01:23:37
【问题描述】:

每当我连接我的客户端以将数据发送到我的 WCF Azure 服务时,我都会收到此错误:

“已超出传入邮件的最大邮件大小配额 (65536)。 增加配额,在适当的绑定上使用 MaxReceivedMessageSize 属性 元素。”

我到处都在阅读有关在客户端和服务器配置文件上设置此 MaxReceivedMessageSize 属性的信息。我已经这样做了。

但是,每当我在客户端更新服务引用时,它会将设置拉回默认值 65536。(通过调查 .svcinfo 文件找到)

这使我得出结论,问题一定出在服务端。

我已将它放在我的 web.config 文件中:

<bindings>
  <basicHttpBinding>
    <!--The basicHttpBinding is used for clients which use the generated code to transmit data; the following settings make it possible to send larger amounts to the service-->
    <binding maxReceivedMessageSize="10000000" receiveTimeout="01:00:00">
      <readerQuotas maxStringContentLength="10000000" />
    </binding>
  </basicHttpBinding>
</bindings>

现在,许多帖子都在讨论命名绑定并将其设置在服务器端的服务端点中。像这样的:

<services>
   <service name="YourNamespace.YourServiceClass">
       <endpoint name="endpoint1"
             address="http://server:8888/YourService.svc" 
             binding="basicHttpBinding"
             bindingConfiguration="lageMessageTransfer"
             contract="IYourServiceContract" />
   </service>
</services>

但是,我没有这些服务端点,而且我的服务非常适合小尺寸。

这还需要在哪里设置?

编辑:

更多信息,Tim 似乎在使用默认端点的正确轨道上。我正在使用默认端点。似乎您不能只为该默认端点明确定义服务。或者如果可以的话,我一定是做错了。

但是,您似乎可以按照 Richard 的说明修改默认端点上的绑定。这是通过简单地不为绑定指定名称来完成的。我尝试将我的服务上的值设置为低得多的值,以查看是否有其他东西降低了它们,但它们被完全忽略了。就好像默认端点只是忽略了我创建的绑定。

对于我的整个配置文件:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.diagnostics>
<trace autoflush="true" />
<sources>
  <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
    <listeners>
      <add name="sdt" type="System.Diagnostics.XmlWriterTraceListener" initializeData="logging.e2e" />
    </listeners>
  </source>
</sources>
</system.diagnostics>
<system.web>
<compilation debug="true" targetFramework="4.0">
  <assemblies>
    <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral,  PublicKeyToken=b77a5c561934e089" />
  </assemblies>
</compilation>
</system.web>
<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding maxReceivedMessageSize="100" maxBufferSize="100" receiveTimeout="00:11:00">
      <readerQuotas maxStringContentLength="100" />
    </binding>
  </basicHttpBinding>
</bindings>

<protocolMapping>
  <add scheme="http" binding="basicHttpBinding" />
</protocolMapping>

<behaviors>
  <serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="false" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
<connectionStrings><EDITEDOUT></connectionStrings>
</configuration>

思考为什么新的绑定设置没有被采用?

【问题讨论】:

  • 不幸的是,据我所知,如果您无法修改服务的配置,您就会陷入困境。如果您绝对无法修改服务的配置,则需要采取措施确保您的有效负载小于最大 65536 字节。
  • 我可以修改服务器的配置,但是它不会接受新的设置。

标签: c# .net wcf azure


【解决方案1】:

属性名称 maxReceivedMessageSize 非常明确 - 这完全取决于接收消息的人 - 如果您发送大量数据,那么它是服务,如果您从服务获取大量数据,那么它是客户。服务和客户端不需要此设置的相同值(与许多其他绑定设置不同)

设置未命名的绑定部分通常应该有效,因为在 .NET 4 中,它为未使用 bindingConfiguration 显式指定配置的任何人配置绑定。但是,在上面的示例中,除了 maxReceivedMessageSize 之外,您还需要设置 maxBufferSize,因为您正在缓冲而不是流式传输消息。 maxBufferSize 和 maxReceivedMessageSize 必须相同

【讨论】:

  • 我也设置了 maxBufferSize。同样的问题。如果我查看每当我更新服务引用时都会更新的 configuration.svcinfo 文件,您可以看到它仍在为所有各种属性提取默认值。
  • 客户端将看到默认值,因为这些值在客户端和服务上通常不同。正如我上面所说,它们指的是数据的接收者。你可以试试这个:减少 maxReceivedMessageSize 和 maxBufferSize 使它们低于默认值并发送仍然有效的消息。但是,从服务返回绑定实际 maxReceivedMessageSize 只是为了确保它不会被拾取并且其他东西不会妨碍
  • ((BasicHttpBinding)OperationContext.Current.Host.Description.Endpoints[0].Binding).MaxReceivedMessageSize 应该可以满足您的需求
【解决方案2】:

您的服务端的 Web.config 中没有该部分?如果您使用的是 WCF 4.0,您是否可以使用默认端点?

我不知道您是否可以为默认端点指定绑定,但您可能想尝试通过 Web.config 部分指定端点并将 bindingConfiguration 设置为您部分中指定的绑定。

【讨论】:

  • 我尝试明确定义一个没有地址的新服务端点: 不走运,尽管这似乎是在正确的道路上。有没有办法追踪并查看配置中是否输入错误?
  • 你能发布整个配置文件吗?配置文件中的某些内容可能不匹配。
  • 发布在原始问题中。
  • 这是客户端还是服务器的配置文件?由于客户端正在接收消息,因此必须在服务器的客户端配置文件中调整设置。您在上面编写的配置文件应该工作,因为我了解 4.0 中的更改。
  • 如果您无法编辑服务器的配置文件,那么我相信上面的 GunnerL3510 可以为您提供正确的答案。
猜你喜欢
  • 1970-01-01
  • 2012-06-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-24
相关资源
最近更新 更多