【问题标题】:Which exactly MaxReceivedMessageSize should be increased应该增加哪一个 MaxReceivedMessageSize
【发布时间】:2012-06-15 15:51:04
【问题描述】:

这个问题好像已经被问过千百次了,但是每个人的配置问题都不一样。我有提供图像并接收上传图像请求的 WCF 服务器。上传图片时,当大小超过 65k 时出现错误 400。

我在 WCF 上打开了跟踪,我得到了确切的错误

传入邮件的最大邮件大小配额 (65536) 已达到 超过。要增加配额,请使用 MaxReceivedMessageSize 相应绑定元素上的属性。

我知道我需要增加这个参数,但我只能在我的 web.config 文件中找到它应该在哪里。这是我在 web.config 中的内容:

  <system.serviceModel>
    <protocolMapping>
      <add binding="webHttpBinding" scheme="http" />
    </protocolMapping>
    <services>
      <service behaviorConfiguration="ReportTransferServiceBehavior" name="ReportTransferService">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="ReportTransferService" contract="IReportTransferService"></endpoint>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
        <behavior name="ReportTransferServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceThrottling maxConcurrentCalls="500" maxConcurrentSessions="500" maxConcurrentInstances="500" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior>
          <webHttp helpEnabled="true" />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <domainServices>
      <endpoints>
        <add name="json" type="Microsoft.ServiceModel.DomainServices.Hosting.JsonEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
            maxReceivedMessageSize="2000000" />
      </endpoints>
    </domainServices>
    <bindings>
      <basicHttpBinding>
        <binding name="ReportTransferService" maxReceivedMessageSize="2000000" maxBufferSize="2000000" transferMode="Streamed">
          <readerQuotas maxDepth="2000000" maxStringContentLength="2000000" maxArrayLength="2000000" maxBytesPerRead="2000000" maxNameTableCharCount="2000000" />
          <security mode="None"></security>
        </binding>
      </basicHttpBinding>
    </bindings>
  </system.serviceModel>

我发送图像 (HTTP POST) 的 URL 是 hostname/ReportTransferService.svc/UploadImage。看起来它正在使用某种默认绑定,而不是为更大尺寸配置的 basicHttpBinding

谁能告诉我我的 web.config 出了什么问题?

更新:已解决

我必须在服务配置和 serviceBehavior 配置中为 ReportTransferService 指定完全限定名称,并添加了具有类似限制和指向服务的全新 webHttpBinding 部分以使用此绑定。

感谢您的帮助。

【问题讨论】:

  • 曾经遇到过这样一个奇怪的问题。我已经像你一样为每个配置元素指定了一个更高的值。最后我的一位同事发现问题是因为在合同或服务类型(我不确定)中指定了完整的全名(Namespace.Type,Assembly),但在删除程序集名称后一切正常。
  • 能不能把protocolMapping去掉试试看
  • @Mark - 我在下载和上传时都收到 500 错误
  • 您在删除协议映射后收到该错误?你能追踪并发布错误吗?
  • 类似这样:“xxxxxx/Site/ReportTransferService.svc”的端点没有与 None MessageVersion 的绑定。 'System.ServiceModel.Description.WebHttpBehavior' 仅适用于 WebHttpBinding 或类似的绑定。

标签: wcf iis-7 web-config


【解决方案1】:

您的服务部分应具有完全限定的名称,如下所示:

     <services>
      <service behaviorConfiguration="ReportTransferServiceBehavior" name="namespace.ReportTransferService">
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="ReportTransferService" contract="namespace.IReportTransferService"></endpoint>
      </service>
    </services>

【讨论】:

  • 如果我只进行这两项更改,我在图像下载和上传时都会收到错误 500 System.ServiceModel.ServiceActivationException。
  • 请注意,客户端和服务器上的 readerQuotas 设置需要相同。 500 是内部服务器错误,表示处理过程中服务器方法出现问题。您可以在您的服务上启用跟踪 (msdn.microsoft.com/en-us/library/ms733025.aspx) 以获取错误的确切原因
  • 客户端是JS网页。跟踪已开启。我收到以下错误:“host/Site/ReportTransferService.svc”的端点没有与 None MessageVersion 的绑定。 'System.ServiceModel.Description.WebHttpBehavior' 仅适用于 WebHttpBinding 或类似的绑定。
  • 在您尝试通过 SOAP 绑定执行 REST 调用时有意义。只需将绑定类型从 basicHttpBinding 更改为 webHttpBinding 并相应地更改 webhttpBinding 的 readerQuotas 以及大文件。 (假设您正在使用 HttpWebRequest 类或类似类从客户端执行 ajax 调用)
  • 啊哈...添加了与 basicHttpBinding 相同的部分到 webHttpBinding 并指出服务使用它。看起来它解决了它。我会清理它并确认它,并会标记你的答案。非常感谢!
猜你喜欢
  • 1970-01-01
  • 2011-12-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-17
  • 1970-01-01
  • 2023-04-01
相关资源
最近更新 更多