0

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

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

我还注意到,例如,当我从 Web 客户端发送两个并发请求(例如,从 Firefox 的 2 个不同选项卡同时查询 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 客户端进行一些微调?

提前致谢。

4

0 回答 0