客户端在对WCF服务进行并发调用时收到“java.net.SocketException:Connection reset”

时间:2013-08-09 03:57:51

标签: .net wcf iis-7 .net-4.0 socketexception

我有一个WCF服务(IIS 7,.NET 4,Windows Server 2008 R2 Enterprise),它正由Web客户端查询(用Java编写)。但是,当多个请求同时发送到WCF服务时,客户端会收到"java.net.SocketException: Connection reset"。我浏览了很多线程,并尝试调整我的WCF服务的配置,但问题仍然没有解决。以下是一些更多细节:

web.config(WCF服务):

<?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服务行为: *编辑:根据下面评论中的建议,ServiceBehavior中添加了ConcurrencyMode = ConcurrencyMode.Multiple(但我仍然得到相同的错误)

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple)]

我还注意到,例如,当我从Web客户端发送两个并发请求时(例如,从Firefox的两个不同选项卡同时查询WCF服务),其中一个将返回正确的结果,但另一个将产生SocketException错误。如果我然后重新运行自己返回SocketException错误的查询,它将正常工作。

我还启用了WCF Tracing(此新功能),我看到以下异常消息:

The communication object, System.ServiceModel.Channels.TransportReplyChannelAcceptor+TransportReplyChannel, cannot be used for communication because it has been Aborted.

..使用以下堆栈跟踪:

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

最后,在服务器端,似乎每次发生这种情况时,Visual Studio弹出窗口显示"An unhandled .NET Microsoft framework exception occurred in w3wp.exe [1248]"(我有Visual Studio打开测试我的代码)

任何人都可以帮我解释一下吗?是否可以正确配置WCF服务,但需要从Java Web客户端进行一些微调?

提前致谢。

0 个答案:

没有答案