【问题标题】:RESTful WCF (4.5.2) service errors with "413 Entity Request Too Large"带有“413 Entity Request Too Large”的 RESTful WCF (4.5.2) 服务错误
【发布时间】:2015-11-12 20:42:24
【问题描述】:

这似乎是一个非常常见的问题 - 我已经阅读了 SO 和其他网站上的大量 cmets。问题是,即使在修复了我的配置后,我在发送 ~50K 有效负载时仍然收到 413 错误。

这是服务配置的相关部分...

<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="false" />
<services>
  <service name="Sync.Inbound" behaviorConfiguration="serviceWebConfiguration">
    <endpoint address="" binding="webHttpBinding" bindingName="defaultRest" behaviorConfiguration="web" contract="Sync.IInbound"  />
  </service>
</services>
<bindings>
  <webHttpBinding>
    <binding name="defaultRest" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" transferMode="Streamed">
      <readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxNameTableCharCount="2147483647" />
      <security mode="None" />
    </binding>
  </webHttpBinding>
</bindings>
<behaviors>
  <endpointBehaviors>
    <behavior name="web">
      <webHttp  />
      <dataContractSerializer  maxItemsInObjectGraph="2147483647"  />
    </behavior>
    <behavior name="json">
      <enableWebScript />
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior name="serviceWebConfiguration">
      <serviceMetadata httpGetEnabled="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

我正在通过 httpWebRequest 从一个简单的 C# 控制台应用程序调用它来进行测试...有人看到我在服务配置中缺少的任何内容吗?

【问题讨论】:

    标签: c# .net web-services wcf rest


    【解决方案1】:

    您需要在服务端点元素上将bindingConfiguration属性设置为"defaultRest",否则服务将不会使用指定的绑定配置块。

    上面的示例在“bindingName”属性而不是“bindingConfiguration”属性中显示了绑定配置名称。 因此,您需要更改:

    <endpoint ... bindingName="defaultRest"
    

    到:

    <endpoint ... bindingConfiguration="defaultRest"
    

    例子:

     <system.serviceModel>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="false" />
        <services>
          <service name="Sync.Inbound" behaviorConfiguration="serviceWebConfiguration">
            <endpoint address="" binding="webHttpBinding" bindingConfiguration="defaultRest" ...
          </service>
        </services>
        <bindings>
          <webHttpBinding>
            <binding name="defaultRest" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" transferMode="Streamed">
              <readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxNameTableCharCount="2147483647" />
              <security mode="None" />
            </binding>
          </webHttpBinding>
        </bindings>
    

    参考:
    https://msdn.microsoft.com/en-us/library/ms733099(v=vs.110).aspx
    bindingConfiguration vs bindingName

    【讨论】:

    • 谢谢西摩!完美运行!
    【解决方案2】:

    您可能希望将 maxItemsInObjectGraph 更改为您的服务 dataContractSerializer 以允许更大的集合通过。

    <serviceBehaviors>
      <behavior name="SecureServiceBehavior">
        <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false"/>
        <serviceDebug includeExceptionDetailInFaults="true"/>
        <dataContractSerializer ignoreExtensionDataObject="true" maxItemsInObjectGraph="2147483647"/>
        <serviceTimeouts transactionTimeout="00:03:00"/>
        <serviceThrottling maxConcurrentCalls="10" maxConcurrentSessions="10" maxConcurrentInstances="10"/>
      </behavior>
    </serviceBehaviors>
    

    【讨论】:

      猜你喜欢
      • 2012-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多