远程服务器返回了意外的响应:(413)请求实体过大。 [英] The remote server returned an unexpected response: (413) Request Entity Too Large.

查看:2246
本文介绍了远程服务器返回了意外的响应:(413)请求实体过大。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立一个WCF应用程序服务,使用FW4.0。
我的服务工作正常传输EntiryFramework对象时,服务器和客户端之间。但我有过EF对象从客户端到服务器的问题。

下面我的环境中一些细节:
- 该服务在调试模式下运行本地IIS上
- 我跑这一切都在我的Windows 7
- 我使用Visual Studio 2010上FW4.0

我想一个对象(tblClient)发送到服务器保存记录,但有该错误的保持(413)请求实体过大。
在这里,完整的堆栈:

 发生System.ServiceModel.ProtocolException
      的HResult = -2146233087
      消息=远程服务器返回了意外的响应:(413)请求实体过大。
      来源= mscorlib程序
      堆栈跟踪:
        服务器堆栈跟踪:
           在System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest的要求,HttpWebResponse响应,HttpChannelFactory`1工厂,引发WebException responseException,ChannelBinding channelBinding)
           在System.ServiceModel.Channels.HttpChannelFactory`1.Htt$p$pquestChannel.HttpChannelRequest.WaitForReply(TimeSpan暂停)
           在System.ServiceModel.Channels.RequestChannel.Request(消息消息,时间跨度超时)
           在System.ServiceModel.Dispatcher.RequestChannelBinder.Request(消息消息,时间跨度超时)
           在System.ServiceModel.Channels.ServiceChannel.Call(字符串操作,布尔单向,ProxyOperationRuntime操作,对象[]项,对象[]奏,时间跨度超时)
           在System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime操作)
           在System.ServiceModel.Channels.ServiceChannelProxy.Invoke(即时聊天消息)
        [0]时异常重新抛出:
           在System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(即时聊天reqMsg,即时聊天retMsg)
           在System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&安培; MSGDATA,的Int32型)
           在ClientApp.ServiceReference1.IService.SaveClient(tblClient客户端)
           在ClientApp.ServiceReference1.ServiceClient.SaveClient(tblClient客户端)在C:\\ dufh \\ WPF项目\\ ClientApp \\服务引用\\ ServiceReference1 \\ Reference.vb:行2383
           在ClientApp.ViewModel.ClientViewModel.SaveClient()在C:\\ dufh \\ WPF项目\\ ClientApp \\视图模型\\ ClientViewModel.vb:48行
      的InnerException信息:System.Net.WebException
           的HResult = -2146233079
           消息=远程服务器返回错误:(413)请求实体过大。
           来源=系统
           堆栈跟踪:
                在System.Net.HttpWebRequest.GetResponse()
                在System.ServiceModel.Channels.HttpChannelFactory`1.Htt$p$pquestChannel.HttpChannelRequest.WaitForReply(TimeSpan暂停)
           的InnerException:

我已经做了一些研究,都指向MAXBUFFERSIZE和/或maxBufferPoolSize和/或maxReceivedMessageSize女巫是不是在客户端配置App.Config中足够大。所以我inscresed他们的最大值:
MAXBUFFERSIZE =2147483647maxBufferPoolSize =2147483647maxReceivedMessageSize =2147483647
但还是错误存在。

下面我完整的客户端App.Config中

 <?XML版本=1.0编码=UTF-8&GT?;
<结构>
  <&System.Diagnostics程序GT;
    <来源和GT;
      <! - 这部分定义My.Application.Log日志配置 - >
      <信源名称=DefaultSource交换机名称=DefaultSwitch>
        <&听众GT;
          <添加名称=FileLog/>
          <! - 取消对下面部分写入应用程序事件日志 - >
          <! - <添加名称=事件日志/> - >
        < /听众>
      < /源>
    < /来源>
    <开关与GT;
      <添加名称=DefaultSwitchVALUE =信息/>
    < /开关>
    < sharedListeners>
      <添加名称=FileLog
           键入=Microsoft.VisualBasic.Logging.FileLogTraceListener,Microsoft.VisualBasic程序,版本8.0.0.0 =文化=中性公钥= b03f5f7f11d50a3a,的ProcessorArchitecture = MSIL
           initializeData =FileLogWriter/>
      <! - 取消对以下部分,并与您的应用程序的名称替换APPLICATION_NAME写入应用程序事件日志 - >
      <添加名称=事件日志TYPE =System.Diagnostics.EventLogTraceListenerinitializeData =MVVM采样/>
    < / sharedListeners>
  < /system.diagnostics>
  < system.serviceModel>
    <&绑定GT;
      <&basicHttpBinding的GT;
        <绑定名称=BasicHttpBinding_IServiceMAXBUFFERSIZE =2147483647maxReceivedMessageSize =2147483647/>
      < / basicHttpBinding的>
    < /绑定>
    <客户端>
      <端点地址=HTTP://本地主机:7803 / Service1.svc绑定=basicHttpBinding的
          bindingConfiguration =BasicHttpBinding_IService合同=ServiceReference1.IService
          NAME =BasicHttpBinding_IService/>
    < /客户>
  < /system.serviceModel>
< /结构>

和完整的Web.Config WCF服务Web.Config

 <?XML版本=1.0&GT?;
<结构>  <&的System.Web GT;
    <编译调试=真正的严=false的明确=真targetFramework =4.0/>
  < /system.web>
  < system.serviceModel>    <&绑定GT;
      <&basicHttpBinding的GT;
        <绑定名称=BasicHttpBinding_IServicemaxBufferPoolSize =2147483647maxReceivedMessageSize =2147483647MAXBUFFERSIZE =2147483647>
          < readerQuotas MAXDEPTH =200maxStringContentLength =8388608maxArrayLength =16384maxBytesPerRead =2147483647maxNameTableCharCount =16384/>
        < /&结合GT;
      < / basicHttpBinding的>
    < /绑定>    <&行为GT;
      < serviceBehaviors>
        <&行为GT;
          <! - 为了避免泄露的元数据信息,下面设置为false的价值和部署之前删除上面的元数据终结点 - >
          < serviceMetadata httpGetEnabled =真/>
          <! - 要接收故障中的异常细节进行调试,下面设置为true值。设置为false部署之前,以避免泄露异常信息 - >
          < serviceDebug includeExceptionDetailInFaults =FALSE/>
        < /行为>
      < / serviceBehaviors>
    < /行为>
    < serviceHostingEnvironment multipleSiteBindingsEnabled =真/>
  < /system.serviceModel>
  < system.webServer>
    <模块runAllManagedModulesForAllRequests =真/>
  < /system.webServer>
  <&是connectionStrings GT;
    <添加名称=MaitreEntities connectionString=\"metadata=res://*/Schemat.csdl|res://*/Schemat.ssdl|res://*/Schemat.msl;provider=System.Data.SqlClient;provider连接字符串=安培; QUOT;数据源= INFOFILE2 \\ SQL2008R2;初始目录= 0001ConneryFerland;用户ID = SA;密码= kermit80; multipleactiveresultsets = TRUE;应用=的EntityFramework和放大器; QUOT;的providerName =System.Data.EntityClient/&GT ;
  < /&是connectionStrings GT;
< /结构>
任何帮助将是非常欢迎:-)


解决方案

有关记录

我想我知道了。
从服务的Web.config不具有约束力的信息。
我把这个信息在里面,瞧!

 <&绑定GT;
      <&basicHttpBinding的GT;
        <结合maxBufferPoolSize =2147483647MAXBUFFERSIZE =2147483647maxReceivedMessageSize =2147483647messageEncoding =TEXT>
          < readerQuotas MAXDEPTH =2000000maxStringContentLength =2147483647maxArrayLength =2147483647maxBytesPerRead =2147483647maxNameTableCharCount =2147483647/>
        < /&结合GT;
      < / basicHttpBinding的>
< /绑定>

在这里需要注意的是没有指定绑定的名称。

I'm trying to build a WCF Application service, using FW4.0. My service work correctly when transferring EntiryFramework object between Server and client. But I'm having problem passing EF object from Client to Server.

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

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. 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. So I inscresed them to maximum value : maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" But still the error remain.

Here my full Client 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

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

这篇关于远程服务器返回了意外的响应:(413)请求实体过大。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆