Thursday, 8 August 2013

Client receives "java.net.SocketException: Connection reset" when doing concurrent calls to WCF service

Client receives "java.net.SocketException: Connection reset" when doing
concurrent calls to WCF service

I have a WCF service (IIS 7, .NET 4, Windows Server 2008 R2 Enterprise)
which is being queried by a web client (written in Java). However, when
more than one requests are sent concurrently to the WCF service, the
client receives a "java.net.SocketException: Connection reset". I have
browsed a lot of the threads and tried to adjust the configuration of my
WCF service but the issue is still not fixed. Below are some more details:
web.config (of WCF service):
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<customErrors mode="Off"/>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647" closeTimeout="00:10:00"
openTimeout="00:10:00" receiveTimeout="00:10:00"
sendTimeout="00:10:00" />
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="Alpha.BetaBehavior">
<!-- 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="true"/>
<!-- below is for huge files-->
<!-- dataContractSerializer maxItemsInObjectGraph="2147483647" /
-->
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="BetaEndpointBehavior">
<webHttp helpEnabled="true"/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="Alpha.Beta" behaviorConfiguration="Alpha.BetaBehavior">
<endpoint address="" kind="webHttpEndpoint"
behaviorConfiguration="BetaEndpointBehavior"
binding="webHttpBinding" contract="Alpha.IBeta">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding"
contract="IMetadataExchange"/>
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
<diagnostics wmiProviderEnabled="true">
<messageLogging
logEntireMessage="true"
logMalformedMessages="true"
logMessagesAtServiceLevel="true"
logMessagesAtTransportLevel="true"
maxMessagesToLog="3000"
/>
</diagnostics>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="Information,
ActivityTracing" propagateActivity="true" >
<listeners>
<add name="xml"/>
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging">
<listeners>
<add name="xml"/>
</listeners>
</source>
<source name="myUserTraceSource" switchValue="Information,
ActivityTracing">
<listeners>
<add name="xml"/>
</listeners>
</source>
</sources>
<sharedListeners>
<add name="xml"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="C:\inetpub\wwwroot\bin\RequestLogs\Traces.svclog"
/>
</sharedListeners>
</system.diagnostics>
</configuration>
WCF Service Behavior:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
I have also noticed that when, for example, I send two concurrent requests
from the web client (e.g. querying the WCF service concurrently from 2
different tabs of Firefox), one of them will return correct results but
the other will yield the SocketException error. If I then rerun the query
which returned the SocketException error by itself, it will work
correctly.
I have also enabled WCF Tracing (new to this), and I see the following
Exception Message:
The communication object,
System.ServiceModel.Channels.TransportReplyChannelAcceptor+TransportReplyChannel,
cannot be used for communication because it has been Aborted.
..with the following stack trace:
System.ServiceModel.Channels.CommunicationObject.ThrowIfAborted()
System.ServiceModel.Channels.InputQueueChannel`1.EndDequeue(IAsyncResult
result, TDisposable&amp; item)
System.ServiceModel.Channels.ReplyChannel.EndTryReceiveRequest(IAsyncResult
result, RequestContext&amp; context)
System.ServiceModel.Dispatcher.ReplyChannelBinder.EndTryReceive(IAsyncResult
result, RequestContext&amp; requestContext)
System.ServiceModel.Dispatcher.ErrorHandlingReceiver.EndTryReceive(IAsyncResult
result, RequestContext&amp; requestContext)
System.ServiceModel.Dispatcher.ChannelHandler.AsyncMessagePump(IAsyncResult
result)
System.ServiceModel.Dispatcher.ChannelHandler.OnAsyncReceiveComplete(IAsyncResult
result)
System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)
System.Runtime.AsyncResult.Complete(Boolean completedSynchronously)
System.Runtime.InputQueue`1.AsyncQueueReader.Set(Item item)
System.Runtime.InputQueue`1.Shutdown(Func`1 pendingExceptionGenerator)
System.ServiceModel.Channels.InputQueueChannel`1.OnClosing()
System.ServiceModel.Channels.CommunicationObject.Abort()
System.ServiceModel.Dispatcher.ListenerHandler.AbortChannels()
System.ServiceModel.Dispatcher.ListenerHandler.OnAbort()
System.ServiceModel.Channels.CommunicationObject.Abort()
System.ServiceModel.Dispatcher.ChannelDispatcher.OnAbort()
System.ServiceModel.Channels.CommunicationObject.Abort()
System.ServiceModel.ServiceHostBase.OnAbort()
System.ServiceModel.Channels.CommunicationObject.Abort()
System.ServiceModel.ServiceHostingEnvironment.HostingManager.Abort()
System.ServiceModel.ServiceHostingEnvironment.HostingManager.Stop(Boolean
immediate)
System.Web.Hosting.HostingEnvironment.StopRegisteredObjects(Boolean
immediate)
System.Web.Hosting.HostingEnvironment.InitiateShutdownWorkItemCallback(Object
state)
System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
System.Threading.ExecutionContext.Run(ExecutionContext executionContext,
ContextCallback callback, Object state, Boolean ignoreSyncCtx)
System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
System.Threading.ThreadPoolWorkQueue.Dispatch()
System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
Finally, on the server side, it appears that each time this occurs a
Visual Studio popup appears saying that "An unhandled .NET Microsoft
framework exception occurred in w3wp.exe [1248]" (I have Visual studio
open testing my code)
Can anyone help me shed some light into this? Could it be that the WCF
service is properly configured but some fine-tuning needs to happen from
the Java web-client?
Thanks in advance.

No comments:

Post a Comment