40

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

7 Answers 7

81

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.

Sign up to request clarification or add additional context in comments.

7 Comments

Thanks! "web.config from the service" means: "web.config at the server".
Thanks. Took me a few hours trying to find which binding was missing and it was the service side web.config binding without a name like in your example.
Thanks a lot! "did not have a name specified" should be in bold :]
Don't forget to add the bindingConfiguration name on your endpoint
@uriz - OP doesn't have an endpoint defined in the posted config. The binding defined above will be used as the binding for any basicHttpBinding endpoints covered by that config (because of the absence of the name attribute).
|
14

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. WCF is providing a default endpoint along with a default binding (basicHttpBinding unless you overrode it in the protocolMapping section of the config file).

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:

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

Or you define an endpoint explicitly in the config and assign your binding configuration to the bindingConfiguration attribute of the endpoint.

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

1 Comment

Thanks for your help Tim, but the error still remain. I'll set my WCF service aside for a while. And let it simmer for a while ...
2

This can also be due to IIS restriction. IIS Manager-> Select your application-> Features Veiw->Request Filtering->Edit Feature Settings->Maximum Allowed Content Length 30000000(28.6M)-> Increase the value

Comments

0

If you create custom binding e.g. 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 endpointas,

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

Comments

0

Another way to fix this and have a better look at web.config file, is to edit the web.config file with the "Microsoft Service Configuration Editor" (C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\SvcConfigEditor.exe)

Comments

0

if no binding is specified and httpsgetenabled is true then you may need to set basichttpsbinding in your service application's web.config

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

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.