Remove size limit of WCF-Service answers
I have created an WCF-Service that runs an operation on a W2008-Server and returns a datastructure as a result. Problem is, that this result can be larger, than the standard service configuration seems to accept. So I tried to increase (or remove) this maximum size, but it seems, I didn't found the correct properties.
In the App.config of the WCF, I changed the following values of my basicHttpBinding:
- MaxBufferPoolSize -> 6553600
- MaxBufferSize -> 6553600
- MaxReceiveMessageSize -> 6553600
ReaderQuotas:
- MaxArrayLenght -> 0
- MaxBytesPerRead -> 0
- MaxDepth -> 0
- MaxNameTableCharCount -> 0
- MaxStringContentLength -> 0
I then start the WCF-Testclient to call the service. I make sure, that the values for the properties of the basicHttpBinding are equal to the ones in the configuration. When I call the service in a way, that the result set is rather small, everything works fine. But when this size is increased, I eventually get the error (translated from german):
Error while receiving http answer for http://localhost:8731/Design_Time_Addresses/DiscoDataSource/Service1/. Possible reasons: Endpointbinding doesn't use the HTTP protocol or the HTTP-requestcontext was canceled by the server.
Server stack trace:
at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
at System.ServiceModel.Channels.HttpChannelFactory.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.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)开发者_StackOverflow中文版
I would like to configure the service to return the result regardless of the size. Anybody knows, where I need to change the configuration?
Thanks in advance, Frank
If you have a large number of objects that are being serialized, WCF will hit a configured limit and barf. You've tried all the standard items, but there's one you left out: maxItemsInObjectGraph
. Just like other config values, you'll need to set it both server-side and client-side. Here's a sample config snippit with an unnecessarily large value:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483646"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="ClientBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483646"/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
I'm obviously omitting a lot of tags in favor of illustrating where maxItemsInObjectGraph
appears in your .config file.
Have you changed those values on both the client and the server side as well?? You need to change them on both ends of the communication - only then it'll work.
If you haven't changed them on the server-side, the smaller value of both (client and server value) will "win".
Maybe, however, it's really just your timeout settings that cause the server to abort. On your binding, you can tweak the timeouts - by default, it's 60 seconds - so if grabbing the data and assembling it as needed takes more time, you'd need to adjust the SendTimeout
on the binding, rather than the size settings.....
精彩评论