我这里有一个WCF双工服务,要求客户端的回调应该超时10秒,因此我的服务的web.config文件如下所示:
<bindings>
<basicHttpBinding>
<binding name="simulatorEndpoint" closeTimeout="00:00:10" openTimeout="00:00:10"
receiveTimeout="00:00:10" sendTimeout="00:00:10" allowCookies="false"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
<wsDualHttpBinding>
<binding name="wsdualEndpoint" closeTimeout="00:00:10" openTimeout="00:00:10"
receiveTimeout="00:00:10" sendTimeout="00:00:10" bypassProxyOnLocal="false"
transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536" clientBaseAddress="http://localhost:1235"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:00:10" />
<security mode="Message">
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsDualHttpBinding>
</bindings>
在客户端,app.config文件中的绑定具有相同的超时值。
现在的效果是,如果客户端向服务器发送请求,则Timeout为10秒。但另一方面,如果服务向客户端发送回调,则超时为1分钟。这很奇怪......很明显,超时是在客户端正确设置的..但不在服务上......我如何更改服务的超时?
PS:我正在使用Visual Studio 2010及其调试模式与认可的ASP.NET Development Server 10.0.0.0
答案 0 :(得分:4)
binding timeouts ...
的简要总结客户方:
- SendTimeout用于初始化OperationTimeout,它控制发送消息的整个交互(包括 在请求 - 回复情况下接收回复消息)。这个超时也是 从CallbackContract方法发送回复消息时适用。
- 打开和关闭通道时使用OpenTimeout和CloseTimeout(当没有传递显式超时值时)。
- 未使用ReceiveTimeout。
服务器端:
- 发送,打开和关闭超时与客户端(用于回拨)相同。
- ServiceFramework层使用ReceiveTimeout来初始化会话空闲超时。
[编辑:一些代码] 另请尝试将此添加到您的服务配置
<behaviors>
<endpointBehaviors>
<behavior name="MyCallbackBehavior">
<callbackTimeouts transactionTimeout="00:00:10"/>
</behavior>
</endpointBehaviors>
<behaviors>
然后将行为添加到您的终端
<endpoint behaviorConfiguration="MyCallbackBehavior" />
答案 1 :(得分:3)
好的,我发现了错误......
我使用
进行了bindingConfiguration <wsDualHttpBinding>
<binding name="wsdualEndpoint" closeTimeout="00:00:10" openTimeout="00:00:10"
receiveTimeout="00:00:10" sendTimeout="00:00:10" bypassProxyOnLocal="false"
transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536" clientBaseAddress="http://localhost:1235"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:00:10" />
<security mode="Message">
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsDualHttpBinding>
但是线索是这是我对端点的声明:
<endpoint address="dual" binding="wsDualHttpBinding"
name="wsdualEndpoint" contract="INotificationService"/>
因为我的假设是他会获取上面定义的绑定配置并将它们用于我的端点,但这是错误的,我必须将bindingConfiguration =“CONFIGURATION的名称”添加到端点声明。
因此,仅供参考,我的工作配置如下:
<wsDualHttpBinding>
<binding name="MywsdualEndpoint" sendTimeout="00:00:05" bypassProxyOnLocal="false"
transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true"/>
<security mode="Message">
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsDualHttpBinding>
并且正确的端点声明是:
<endpoint address="dual" binding="wsDualHttpBinding" bindingConfiguration="MywsdualEndpoint" contract="INotificationService"/>