2013-12-13 90 views
27

我正在尝试使用FW4.0构建WCF应用程序服务。 在服务器和客户端之间传输EntiryFramework对象时,我的服务工作正常。但我有问题从客户端传递EF对象到服务器。远程服务器返回了意外响应:(413)请求实体太大。

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

我想发送一个对象(tblClient)到服务器来保存记录,但一直有错误(413)请求实体太大。 这里堆满:

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: 

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

这里我完整的客户端的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> 

和全面的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 :-) 

回答

58

为了记录

我想我得到了它。 服务中的Web.Config没有绑定信息。 我把这个信息放进去了,瞧!

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

请注意,这里的绑定没有指定名称。

+4

谢谢! “从服务的web.config”是指:“在服务器上的web.config”。 –

+1

谢谢。花了我几个小时试图找出哪些绑定丢失,这是服务端web.config绑定没有像你的例子中的名称。 –

+0

谢谢!在我的情况下,我有一个网络服务,也错过了节点 - 谢谢雨果! –

11

你没有明确的终点(意思是一个定义你的配置文件),因此您声明的绑定配置(“BasicHttpBinding_IService”)未被使用。 WCF提供默认端点以及默认绑定(basicHttpBinding,除非您在配置文件的protocolMapping部分中覆盖它)。

有两种方式在服务的配置文件来解决此问题:

您可以通过删除name属性使“BasicHttpBinding_IService”配置默认:

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

或者你明确地定义端点在配置中,并将绑定配置分配给端点的bindingConfiguration属性。

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

感谢您的帮助蒂姆,但错误仍然存​​在。我将暂时搁置我的WCF服务。 让它煨一会儿... – Hugo

0

如果您创建自定义绑定,例如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> 

为了避免413错误,不要foreget到指定bindingConfiguration = “MybasicBinding”服务端点如,

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

另一种方式来解决这个问题,有一个使用“Microsoft Service Configuration Editor”(C:\ Program Files(x86)\ Microsoft SDK \ Windows \ v8.1A \ bin \ NETFX 4.5.1工具编辑web.config文件\ SvcConfigEditor.exe)

相关问题