简体   繁体   English

WCF服务返回意外响应:(413)请求实体太大

[英]Unexpected response returned by WCF Service: (413) Request Entity Too Large

I've implemented a small set of REST services using WCF. 我使用WCF实现了一小组REST服务。 One of the services recieves a large amount of data. 其中一项服务收到大量数据。 When calling it (this is when runnig it from visual studio - I haven't deployed itto a production server yet) I get the error 在调用它时(这是从visual studio运行它 - 我还没有将它部署到生产服务器)我得到了错误

The remote server returned an error: (413) Request Entity Too Large. 远程服务器返回错误:(413)请求实体太大。

My web config 我的网络配置

<binding name="BasicHttpBinding_ISalesOrderDataService" 
         closeTimeout="00:10:00"
         openTimeout="00:10:00" 
         receiveTimeout="00:10:00" 
         sendTimeout="00:10:00"
         allowCookies="false" 
         bypassProxyOnLocal="false" 
         hostNameComparisonMode="StrongWildcard"
         maxBufferPoolSize="2147483647" 
         maxBufferSize="2147483647" 
         maxReceivedMessageSize="2147483647"
         textEncoding="utf-8" 
         transferMode="Buffered" 
         useDefaultWebProxy="true"
         messageEncoding="Text">
  <readerQuotas maxDepth="2000000" 
                maxStringContentLength="2147483647"
                maxArrayLength="2147483647" 
                maxBytesPerRead="2147483647"
                maxNameTableCharCount="2147483647" />
  <security mode="None">
    <transport clientCredentialType="None" 
               proxyCredentialType="None" 
               realm="" />
    <message clientCredentialType="UserName" 
             algorithmSuite="Default" />
  </security>
</binding>

Seem you exceed quota augment those value. 似乎超过配额会增加这些价值。

 maxReceivedMessageSize="2000000" maxBufferSize="2000000">

(or review your query for a lower result when possible) (或在可能的情况下检查您的查询以获得较低的结果)

if nothing work check here its like comon probleme. 如果没有任何工作,请在这里检查它就像comon probleme。

The remote server returned an error: (413) Request Entity Too Large 远程服务器返回错误:(413)请求实体太大

I'm afraid your client is fine but you need to check the server web.config 我担心你的客户端很好,但你需要检查服务器web.config

add value the same way you did for your client 以与客户端相同的方式增加价值

<bindings>
      <basicHttpBinding>
        <binding maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
          <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
        </binding>
      </basicHttpBinding>
</bindings>

In addition to increasing message size and buffer size quotes, consider also increase maxItemsInObjectGraph for serializer. 除了增加消息大小和缓冲区大小引号外,还要考虑增加序列化程序的maxItemsInObjectGraph It can matter if your object has complex structure or array of objects inside. 如果您的对象内部具有复杂的结构或对象数组,则可能很重要。 Our typical setting look so 我们的典型设置看起来如此

 <behaviors>
  <endpointBehaviors>
    <behavior name="GlobalEndpoint">
      <dataContractSerializer maxItemsInObjectGraph="1365536" />
    </behavior>
 </behaviors>
 <serviceBehaviors>
    <behavior name="GlobalBehavior">
      <dataContractSerializer maxItemsInObjectGraph="1365536" />
    </behavior>
 </serviceBehaviors>

And additionaly what Zwan has proposed 另外还有Zwan提出的建议

If I understand you correctly your request is the one that is delivering large amounts of data. 如果我理解正确,您的请求就是提供大量数据的请求。 That means that you have to edit the maxRecievedMessageSize like @Zwan have written. 这意味着您必须编辑像@Zwan所写的maxRecievedMessageSize。 Not in the client's config but in the rest services config to allow big requests of data. 不在客户端的配置中,而是在其他服务配置中允许大量数据请求。

尝试增加web.config文件中的“maxItemsInObjectGraph”大小,因为此更改对我有用 。有关详细信息,请参阅。

If you host the wcf rest service in a asp.net application, the httpRuntime limits must also be set because wcf service is running in ASP .NET compatibilty mode. 如果您在asp.net应用程序中托管wcf rest服务,还必须设置httpRuntime限制,因为wcf服务在ASP .NET兼容模式下运行。 Note that maxRequestLength has value in kilobytes 请注意, maxRequestLength具有以千字节为单位的值

<configuration> <system.web>
<httpRuntime maxRequestLength="10240" /> </system.web> </configuration>

Refer at The remote server returned an error: (413) Request Entity Too Large 请参阅远程服务器返回错误:(413)请求实体太大

More advice should make Dispose, destructor for services 更多建议应该使Dispose,析构函数服务

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Multiple, MaxItemsInObjectGraph = 2147483647)]
[GlobalErrorBehaviorAttribute(typeof(GlobalErrorHandler))]
public partial class YourService : IYourService
{

    // Flag: Has Dispose already been called? 
    bool disposed = false;
    // Instantiate a SafeHandle instance.
    SafeHandle handle = new SafeFileHandle(IntPtr.Zero, true);

    // Public implementation of Dispose pattern callable by consumers. 
    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    // Protected implementation of Dispose pattern. 
    protected virtual void Dispose(bool disposing)
    {
        if (disposed)
            return;

        if (disposing)
        {
            handle.Dispose();
            // Free any other managed objects here. 
            //
        }

        // Free any unmanaged objects here. 
        //
        disposed = true;
    }

    ~YourService()  // destructor
    {
      Dispose();
    }

} }

Hope it helps! 希望能帮助到你!

Since ok with maxRecievedMessageSize, you can check "IIS Request Filtering" where maximum length of content in a request, in bytes 从maxRecievedMessageSize开始,您可以检查“IIS请求过滤”,其中请求中的内容的最大长度,以字节为单位

Also in the IIS – “UploadReadAheadSize” that prevents upload and download of data greater than 49KB. 同样在IIS中 - “UploadReadAheadSize”,可防止上传和下载大于49KB的数据。 The value present by default is 49152 bytes and can be increased up to 4 GB. 默认情况下,该值为49152字节,最大可增加到4 GB。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 上载大图像时WCF服务错误-远程服务器返回意外响应:(413)请求实体太大 - WCF service error while uploading large images - the remote server returned an unexpected response: (413) request entity too large WCF 4.5:发生意外错误:远程服务器返回了意外响应:(413)请求实体太大 - WCF 4.5: An unexpected error occurred: The remote server returned an unexpected response: (413) Request Entity Too Large WCF:远程服务器返回了意外的响应:(413)请求实体太大 - WCF : The remote server returned an unexpected response: (413) Request Entity Too Large 远程服务器返回了意外的响应:(413)请求实体太大 - The remote server returned an unexpected response: (413) Request Entity Too Large 错误:远程服务器返回了意外的响应:(413)请求实体太大 - Error: the remote server returned an unexpected response: (413) Request Entity Too Large 远程服务器返回意外响应:(413) 请求实体太大。 - The remote server returned an unexpected response: (413) Request Entity Too Large. c# - 远程服务器返回了意外响应:(413) 请求实体太大 - c# - The remote server returned an unexpected response: (413) Request Entity Too Large 远程服务器返回意外响应:(413)请求实体太大。? - The remote server returned an unexpected response: (413) Request Entity Too Large.? System.ServiceModel.ProtocolException:远程服务器返回了意外的响应:(413)请求实体太大 - System.ServiceModel.ProtocolException: The remote server returned an unexpected response: (413) Request Entity Too Large 远程服务器返回意外响应:(413) Request Entity too Large in wsHttpBinding - The remote server returned an unexpected response: (413) Request Entity too Large in wsHttpBinding
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM