简体   繁体   English

远程服务器返回意外响应:(413) 请求实体太大。

[英]The remote server returned an unexpected response: (413) Request Entity Too Large.

I'm trying to build a WCF Application service, using FW4.0.我正在尝试使用 FW4.0 构建 WCF 应用程序服务。 My service work correctly when transferring EntiryFramework object between Server and client.在服务器和客户端之间传输 EntiryFramework 对象时,我的服务工作正常。 But I'm having problem passing EF object from Client to Server.但是我在将 EF 对象从客户端传递到服务器时遇到了问题。

Here some more detail about my environment: - The service is running in debug mode locally on IIS - I'm running all this on my Windows 7 - I'm using Visual Studio 2010 on FW4.0这里有一些关于我的环境的更多细节: - 该服务在 IIS 上本地以调试模式运行 - 我在 Windows 7 上运行所有这些 - 我在 FW4.0 上使用 Visual Studio 2010

I'm trying to send a object (tblClient) to server to save the record, but a keep having the error (413) Request Entity Too Large.我正在尝试将对象 (tblClient) 发送到服务器以保存记录,但一直出现错误 (413) 请求实体太大。 Here the full stack:这里是完整的堆栈:

System.ServiceModel.ProtocolException occurred
      HResult=-2146233087
      Message=The remote server returned an unexpected response: (413) Request Entity Too Large.
      Source=mscorlib
      StackTrace:
        Server stack trace:
           at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory`1 factory, WebException responseException, ChannelBinding channelBinding)
           at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
           at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
           at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
           at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
           at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
           at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
        Exception rethrown at [0]:
           at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
           at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
           at ClientApp.ServiceReference1.IService.SaveClient(tblClient client)
           at ClientApp.ServiceReference1.ServiceClient.SaveClient(tblClient client) in C:\dufh\WPF Project\ClientApp\Service References\ServiceReference1\Reference.vb:line 2383
           at ClientApp.ViewModel.ClientViewModel.SaveClient() in C:\dufh\WPF Project\ClientApp\ViewModel\ClientViewModel.vb:line 48
      InnerException: System.Net.WebException
           HResult=-2146233079
           Message=The remote server returned an error: (413) Request Entity Too Large.
           Source=System
           StackTrace:
                at System.Net.HttpWebRequest.GetResponse()
                at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
           InnerException:

I've do some research and all point to the maxBufferSize and/or maxBufferPoolSize and/or maxReceivedMessageSize witch is not large enough in the Client config App.Config.我做了一些研究,并且都指出客户端配置 App.Config 中的 maxBufferSize 和/或 maxBufferPoolSize 和/或 maxReceivedMessageSize 不够大。 So I inscresed them to maximum value : maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" But still the error remain.所以我将它们增加到最大值: maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" 但错误仍然存​​在。

Here my full Client App.Config这是我的完整客户端 App.Config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.diagnostics>
    <sources>
      <!-- This section defines the logging configuration for My.Application.Log -->
      <source name="DefaultSource" switchName="DefaultSwitch">
        <listeners>
          <add name="FileLog"/>
          <!-- Uncomment the below section to write to the Application Event Log -->
          <!--<add name="EventLog"/>-->
        </listeners>
      </source>
    </sources>
    <switches>
      <add name="DefaultSwitch" value="Information" />
    </switches>
    <sharedListeners>
      <add name="FileLog"
           type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
           initializeData="FileLogWriter"/>
      <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
      <add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="MVVM Sampling"/>
    </sharedListeners>
  </system.diagnostics>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"/>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:7803/Service1.svc" binding="basicHttpBinding"
          bindingConfiguration="BasicHttpBinding_IService" contract="ServiceReference1.IService"
          name="BasicHttpBinding_IService" />
    </client>
  </system.serviceModel>
</configuration>

and the full Web.Config WCF service Web.Config和完整的 Web.Config WCF 服务 Web.Config

<?xml version="1.0"?>
<configuration>

  <system.web>
    <compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>

    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
          <readerQuotas maxDepth="200" maxStringContentLength="8388608" maxArrayLength="16384" maxBytesPerRead="2147483647" maxNameTableCharCount="16384" />
        </binding>
      </basicHttpBinding>
    </bindings>

    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />


  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
  <connectionStrings>
    <add name="MaitreEntities" connectionString="metadata=res://*/Schemat.csdl|res://*/Schemat.ssdl|res://*/Schemat.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=INFOFILE2\SQL2008R2;initial catalog=0001ConneryFerland;user id=sa;password=kermit80;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>


Any help would be very welcome :-)

For the record备案

I think I got it.我想我明白了。 The Web.Config from the service does not have the binding information.来自服务的 Web.Config 没有绑定信息。 I placed this info in it, and voila!我把这个信息放在里面,瞧!

<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>

Note here that the binding did not have a name specified.请注意,这里绑定没有指定名称。

You don't have an explicit endpoint (meaning one defined in your config file) for your service, so the binding configuration you declared ("BasicHttpBinding_IService") isn't being used.您的服务没有明确的端点(即在您的配置文件中定义的端点),因此您声明的绑定配置(“BasicHttpBinding_IService”)没有被使用。 WCF is providing a default endpoint along with a default binding ( basicHttpBinding unless you overrode it in the protocolMapping section of the config file). WCF 提供了一个默认端点以及一个默认绑定( basicHttpBinding除非您在配置文件的protocolMapping部分覆盖它)。

You have two ways to resolve this in your service's config file:您有两种方法可以在服务的配置文件中解决此问题:

You can make the "BasicHttpBinding_IService" configuration the default by removing the name attribute:您可以通过删除name属性使“BasicHttpBinding_IService”配置成为默认配置:

<binding maxBufferPoolSize="2147483647".....

Or you define an endpoint explicitly in the config and assign your binding configuration to the bindingConfiguration attribute of the endpoint.或者您在配置中明确定义一个端点并将您的绑定配置分配给端点的bindingConfiguration属性。

<services>
    <endpoint address="" 
              binding="basicHttpBinding"
              bindingConfiguration="BasicHttpBinding_IService"     
              contract="ServiceReference1.IService"  />
</services>

If you create custom binding eg MybasicBinding,如果您创建自定义绑定,例如 MybasicBinding,

  <basicHttpBinding>
      <binding name="MybasicBinding" closeTimeout="01:00:00" openTimeout="01:00:00" receiveTimeout="01:00:00" sendTimeout="01:00:00"
               maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" >
            <readerQuotas maxDepth="32" maxBytesPerRead="200000000" 
             maxArrayLength="200000000" maxStringContentLength="200000000" />
      </binding>
  </basicHttpBinding>

To avoid the 413 error, Do not foreget to Specify the bindingConfiguration="MybasicBinding" for service endpoint as,为避免 413 错误,不要忘记将服务端点bindingConfiguration="MybasicBinding"指定为,

<endpoint address="" binding="basicHttpBinding" bindingConfiguration="MybasicBinding" contract="WCFService.IService" />

解决此问题并更好地查看 web.config 文件的另一种方法是使用“Microsoft 服务配置编辑器”(C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v8.1A) 编辑 web.config 文件\\bin\\NETFX 4.5.1 Tools\\SvcConfigEditor.exe)

if no binding is specified and httpsgetenabled is true then you may need to set basichttpsbinding in your service application's web.config如果未指定绑定且 httpsgetenabled 为 true,则您可能需要在服务应用程序的 web.config 中设置 basichttpsbinding

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

I was getting this error.我收到这个错误。 I discovered that I had created the binding configuration, but failed to set the endpoint to that configuration.我发现我已经创建了绑定配置,但未能将端点设置为该配置。 Therefore, the endpoint was using an unnamed binding configuration with the default settings.因此,端点使用具有默认设置的未命名绑定配置。 So, maxReceivedMessageSize was 65k.因此,maxReceivedMessageSize 为 65k。

暂无
暂无

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

相关问题 远程服务器返回意外响应:(413)请求实体太大。? - 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 WCF 4.5:发生意外错误:远程服务器返回了意外响应:(413)请求实体太大 - WCF 4.5: An unexpected error occurred: The remote server returned an unexpected response: (413) Request Entity Too Large Azure云服务“远程服务器返回错误:(413)请求实体太大。” - Azure Cloud Service “The remote server returned an error: (413) Request Entity Too Large.” WCF服务“远程服务器返回错误:(413)请求实体太大。” - WCF Service “The remote server returned an error: (413) Request Entity Too Large.” WCF:远程服务器返回了意外的响应:(413)请求实体太大 - WCF : 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 c# - 远程服务器返回了意外响应:(413) 请求实体太大 - c# - 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