Trouble handling a WCF call that returns a LOT of data
I've got a NetTcp WCF service running on my server, and a client that's calling one of the methods of that service asynchronously.
When the server开发者_Go百科 returns small amounts of data, everything is hunky dory. But when there's a lot of data to return, the client summarily crashes, without even so much as an exception to catch.
From what I can see, the crash happens almost immediately after the server returns the data.
Any ideas how to debug this? Is there some setting on the service that I should be tweaking to allow me to return large volumes of data in this call?
My approach here is:
- split the data into several calls, essentially pages of (say) 500 rows each. A handful of round-trips (rather than 1) won't hurt latency, but will increase stability
- change the serializer (I'm biased here, but I like protobuf-net) to reduce the bandwidth needed per call, ideally in combination with enabling MTOM
That should reduce the bandwidth in the different ways in parallel, and fix the issue.
Try increasing the maxReceivedMessageSize="SomeMaxSize"
<binding name="BasicHttp" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="true" hostNameComparisonMode="StrongWildcard"
maxBufferSize="1000000" maxBufferPoolSize="524288" maxReceivedMessageSize="1000000"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binding>
You can also enable tracing for your service by adding below section to your web.config.
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
<listeners>
<add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\log\Traces.svclog" />
</listeners>
</source>
</sources>
Increasing the max size is not the best solution, if your service is hosted in IIS at some point it will crash. If you are using NetTCP bindig the best way of doing this is by exposing a Stream over TCP, look here.
精彩评论