WCF 轮询双工会话
我有一个 Silverlight 客户端,它尝试创建会话,但服务器没有响应(客户端抛出超时异常)。在服务器日志中我发现:
<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
<System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
<EventID>0</EventID>
<Type>3</Type>
<SubType Name="Warning">0</SubType>
<Level>4</Level>
<TimeCreated SystemTime="2011-03-01T15:47:17.3951653Z" />
<Source Name="System.ServiceModel.PollingDuplex" />
<Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" />
<Execution ProcessName="w3wp" ProcessID="3820" ThreadID="17" />
<Channel />
<Computer>VM662</Computer>
</System>
<ApplicationData>
<TraceData>
<DataItem>
<TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Warning">
<TraceIdentifier>http://msdn.microsoft.com/ru-RU/library/System.ServiceModel.PollingDuplex.ListenerClosed.aspx</TraceIdentifier>
<Description>The service no longer accepts new sessions. An http error was returned.</Description>
<AppDomain>/LM/W3SVC/1/ROOT-1-129434680323302677</AppDomain>
<Source>System.ServiceModel.Channels.PollingDuplexChannelListener/40535505</Source>
<ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/PollingDuplexTraceRecord">
<clientAddress>http://docs.oasis-open.org/ws-rx/wsmc/200702/anonymous?id=1a9b0998-7fa0-4c53-8268-d4db5e8fad61</clientAddress>
<serverAddress>http://porn.com/getgirls.svc</serverAddress>
<sessionId>3d21efa1-1204-433a-8881-06cd6da7de60</sessionId>
<HttpStatusCode>NotFound</HttpStatusCode>
</ExtendedData>
</TraceRecord>
</DataItem>
</TraceData>
<System.Diagnostics xmlns="http://schemas.microsoft.com/2004/08/System.Diagnostics">
<LogicalOperationStack></LogicalOperationStack>
<Timestamp>2545401989404</Timestamp>
</System.Diagnostics>
</ApplicationData>
</E2ETraceEvent>
这是什么意思?为什么具有轮询双工绑定的 WCF 服务无法“接受新会话”?
更新: 服务器有大约20个并发会话请求,其中大多数都失败了。但当我开始另一次测试时,一切正常。此问题时常发生,重新启动服务器通常可以解决此问题。 服务器配置:
<system.diagnostics>
<sources>
<source name="System.ServiceModel.PollingDuplex" switchValue="Information">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default"/>
<add name="ServiceModelTraceListener" />
<add name="ServiceModelMessageLoggingListener" />
</listeners>
</source>
<!--<source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default"/>
<add name="ServiceModelMessageLoggingListener"/>
</listeners>
</source>
<source name="System.ServiceModel" switchValue="Warning, ActivityTracing" propagateActivity="true">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default"/>
<add name="ServiceModelTraceListener"/>
</listeners>
</source>-->
</sources>
<sharedListeners>
<add initializeData="c:\pdt_logs\messages.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModelMessageLoggingListener" traceOutputOptions="LogicalOperationStack, DateTime, Timestamp" />
<add initializeData="c:\pdt_logs\web_tracelog.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModelTraceListener" traceOutputOptions="Timestamp" />
</sharedListeners>
<trace autoflush="true" />
</system.diagnostics>
<system.web>
<compilation targetFramework="4.0" />
</system.web>
<system.serviceModel>
<diagnostics>
<messageLogging logEntireMessage="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" />
</diagnostics>
<extensions>
<bindingElementExtensions>
<add name="pollingDuplex" type="System.ServiceModel.Configuration.PollingDuplexElement, System.ServiceModel.PollingDuplex, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</bindingElementExtensions>
</extensions>
<bindings>
<customBinding>
<binding name="PollingDuplexBinding" >
<binaryMessageEncoding>
<readerQuotas maxArrayLength="16777216" maxBytesPerRead="16777216" maxDepth="16777216"
maxNameTableCharCount="16777216" maxStringContentLength="16777216"/>
</binaryMessageEncoding>
<pollingDuplex maxPendingSessions="100"
maxPendingMessagesPerSession="250" inactivityTimeout="24.20:31:23.6470000"/>
<httpTransport maxBufferSize="16777216"
maxReceivedMessageSize="16777216" />
</binding>
</customBinding>
</bindings>
<services>
<service name="PollingDuplexApplication.Services.TestService" behaviorConfiguration="ServiceBehavior">
<endpoint address=""
binding="customBinding"
contract="PollingDuplexApplication.Services.TestService"
bindingConfiguration="PollingDuplexBinding">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceThrottling maxConcurrentCalls="2048" maxConcurrentSessions="2048" maxConcurrentInstances="2048"/>
<dataContractSerializer maxItemsInObjectGraph="16777216"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
I have a Silverlight client which tries to create a session but the server doesn't respond (the client throws a timeout exception). In the server log I've found:
<E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent">
<System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system">
<EventID>0</EventID>
<Type>3</Type>
<SubType Name="Warning">0</SubType>
<Level>4</Level>
<TimeCreated SystemTime="2011-03-01T15:47:17.3951653Z" />
<Source Name="System.ServiceModel.PollingDuplex" />
<Correlation ActivityID="{00000000-0000-0000-0000-000000000000}" />
<Execution ProcessName="w3wp" ProcessID="3820" ThreadID="17" />
<Channel />
<Computer>VM662</Computer>
</System>
<ApplicationData>
<TraceData>
<DataItem>
<TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Warning">
<TraceIdentifier>http://msdn.microsoft.com/ru-RU/library/System.ServiceModel.PollingDuplex.ListenerClosed.aspx</TraceIdentifier>
<Description>The service no longer accepts new sessions. An http error was returned.</Description>
<AppDomain>/LM/W3SVC/1/ROOT-1-129434680323302677</AppDomain>
<Source>System.ServiceModel.Channels.PollingDuplexChannelListener/40535505</Source>
<ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/PollingDuplexTraceRecord">
<clientAddress>http://docs.oasis-open.org/ws-rx/wsmc/200702/anonymous?id=1a9b0998-7fa0-4c53-8268-d4db5e8fad61</clientAddress>
<serverAddress>http://porn.com/getgirls.svc</serverAddress>
<sessionId>3d21efa1-1204-433a-8881-06cd6da7de60</sessionId>
<HttpStatusCode>NotFound</HttpStatusCode>
</ExtendedData>
</TraceRecord>
</DataItem>
</TraceData>
<System.Diagnostics xmlns="http://schemas.microsoft.com/2004/08/System.Diagnostics">
<LogicalOperationStack></LogicalOperationStack>
<Timestamp>2545401989404</Timestamp>
</System.Diagnostics>
</ApplicationData>
</E2ETraceEvent>
What does it mean? Why does the WCF service with polling duplex binding can't "accepts new sessions"?
UPDATE:
Server has about 20 concurrent session requests and most of them were failed. But when I started another test run, all is ok. This issue occurs from time to time, restarting the server usually resolve this problem.
Server configuration:
<system.diagnostics>
<sources>
<source name="System.ServiceModel.PollingDuplex" switchValue="Information">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default"/>
<add name="ServiceModelTraceListener" />
<add name="ServiceModelMessageLoggingListener" />
</listeners>
</source>
<!--<source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default"/>
<add name="ServiceModelMessageLoggingListener"/>
</listeners>
</source>
<source name="System.ServiceModel" switchValue="Warning, ActivityTracing" propagateActivity="true">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default"/>
<add name="ServiceModelTraceListener"/>
</listeners>
</source>-->
</sources>
<sharedListeners>
<add initializeData="c:\pdt_logs\messages.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModelMessageLoggingListener" traceOutputOptions="LogicalOperationStack, DateTime, Timestamp" />
<add initializeData="c:\pdt_logs\web_tracelog.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModelTraceListener" traceOutputOptions="Timestamp" />
</sharedListeners>
<trace autoflush="true" />
</system.diagnostics>
<system.web>
<compilation targetFramework="4.0" />
</system.web>
<system.serviceModel>
<diagnostics>
<messageLogging logEntireMessage="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" />
</diagnostics>
<extensions>
<bindingElementExtensions>
<add name="pollingDuplex" type="System.ServiceModel.Configuration.PollingDuplexElement, System.ServiceModel.PollingDuplex, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</bindingElementExtensions>
</extensions>
<bindings>
<customBinding>
<binding name="PollingDuplexBinding" >
<binaryMessageEncoding>
<readerQuotas maxArrayLength="16777216" maxBytesPerRead="16777216" maxDepth="16777216"
maxNameTableCharCount="16777216" maxStringContentLength="16777216"/>
</binaryMessageEncoding>
<pollingDuplex maxPendingSessions="100"
maxPendingMessagesPerSession="250" inactivityTimeout="24.20:31:23.6470000"/>
<httpTransport maxBufferSize="16777216"
maxReceivedMessageSize="16777216" />
</binding>
</customBinding>
</bindings>
<services>
<service name="PollingDuplexApplication.Services.TestService" behaviorConfiguration="ServiceBehavior">
<endpoint address=""
binding="customBinding"
contract="PollingDuplexApplication.Services.TestService"
bindingConfiguration="PollingDuplexBinding">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceThrottling maxConcurrentCalls="2048" maxConcurrentSessions="2048" maxConcurrentInstances="2048"/>
<dataContractSerializer maxItemsInObjectGraph="16777216"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您使用什么轮询双工模式?我遇到过类似的问题,服务器出现多条消息问题。
解决方案是将我的 PollingDuplexMode 更改为 SingleMessagePerPoll。 WCF 似乎在 MultipleMessagesPerPoll 方面存在一些问题。
您可以在构建绑定时更改模式:
或者在配置文件中。
What polling duplex mode are you using ? I have encountered a similar problem where the server was having problems with multiple messages.
The solution was to change my PollingDuplexMode to SingleMessagePerPoll. It seems WCF has some problems with MultipleMessagesPerPoll.
You can change the mode while constructing the Binding:
Or in the config file.
我想到了两件事,我应该注意的是,我没有使用 Silverlight 完成此操作,仅使用常规 WCF 完成此操作。您可以激活的并发会话数量是有限制的。我认为开箱即用的限制是 16。您可以在此答案中查看如何更改它
使用 WSHttpBinding 时,WCF 并发请求会在服务器上堆积,
或者您可以在 svc 文件编辑器中更改它。如果您在代码中定义服务器,则需要在绑定中找到该选项,但我一时记不起这一点。
您还可能在服务器上进行备份。我建议(在检查您的锁定模型之后)将服务合同标记为 Concurrency=Multiple
two things come to mind and I should note that I haven't done this with Silverlight, only regular WCF. There is a limit to the number of concurrent sessions you can have active. This limit is 16 I believe out of the box. You can see how to change it in this answer
WCF Concurrent requests piling up on the server when using WSHttpBinding
or you can change it in the svc file editor. If you're defining your server in code, you need to find that option in the binding and I can't remember that off the top of my head.
You also may be backing up at the server. I would suggest (after checking your locking model) to mark the service contract as Concurrency=Multiple