Reputation: 183
I am retrieving data from a wcf web service and when data is more than 0.2 million records i get an exception which is as under:
System.ServiceModel.CommunicationException: The underlying connection was closed: A connection that was expected to be kept alive was closed by the server. ---> System.Net.WebException: The underlying connection was closed: A connection that was expected to be kept alive was closed by the server. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
--- End of inner exception stack trace ---
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
--- End of inner exception stack trace ---
Server stack trace:
at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
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)
My web.config looks like this :
<basicHttpBinding>
<binding name="BasicHttpBinding_IService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
messageEncoding="Text" textEncoding="utf-8" transferMode="StreamedResponse" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647"
maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
<binding maxReceivedMessageSize="2147483647" allowCookies="true">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
I am sure that my web service is retrieving data from DB. but is unable to transfer to my web from where i initiated the call. Thanks in advance for any help.
Upvotes: 18
Views: 60961
Reputation: 1
Add following configuration to your wcf service config. And see c:\log\Traces.svclog file. My exception was throw for ;
There was an error while trying to serialize parameter The InnerException message was 'Enum value '0' is invalid for type 'ThyCams2014.XrmBase.new_filingstatu' and cannot be serialized. Ensure that the necessary enum values are present and are marked with EnumMemberAttribute attribute if the type has DataContractAttribute attrienter code herebute.'. Please see InnerException for more details.
<configuration>
<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>
</system.diagnostics>
</configuration>
Upvotes: 0
Reputation: 2964
Had the same error after migrating to a new server.
It finally boiled down to a missing targetFramework
attribute that was not needed on the old server...
<system.web>
<httpRuntime enableVersionHeader="false" targetFramework="4.7.2"/>
</system.web>
Upvotes: 0
Reputation: 4027
I had recently the same problem with a Wcf service within a .Net 4.0 web app. I increased the maxItemsInObjectGraph value and server didn't throw the exception anymore. The documentation here says the default maximum is Int32.MaxValue but I think it is incorrect, the maximum value is 65535.
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<dataContractSerializer maxItemsInObjectGraph="6553500"/>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
The other thing you can do is enable tracing. This is an example of what I have in the web.config:
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true">
<listeners>
<add name="traceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "c:\temp\log\Traces.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
If you double click on the Traces.svclog, windows should open the Microsoft Service Trace Viewer.
If you test your service with the Microsoft WCF Test Client make sure you change the default client config to match the server settings (this includes the client endpoint behavior) to make sure the client can receive the response from the server.
Upvotes: 19
Reputation: 657
we had a loop in our object graph that were returning. I know this probably isn't your problem but I'm adding it here in case anyone else has the same problem. We had includeExceptionDetailInFaults enabled but weren't getting the error in any client (our application or the WCF Test Client). Luckily it showed up in server logs so we were able to find it that way.
We had Parent -> child and child -> parent for two-way navigation, we had to break that link and instead have parent -> child, and the child had an id to lookup the parent, then the error went away.
Upvotes: 0
Reputation: 49
This statement solved my problem:
db.ContextConfiguration.ProxyCreationEnabled = false;
Upvotes: -1
Reputation: 27944
Make your client basicHttpBinding the same as your server binding. This is a verry common error to only change one binding instead of server and client binding.
If that not works you can enable wcf tracing: wcf tracing
That will give you more insights in what the underling problem is.
Upvotes: 2