![](/img/trans.png)
[英]WCF in Silverlight - how to set change the default timeout of 1 minute
[英]Change WCF default timeout
我這里有一個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
綁定超時的簡要總結......
客戶端:
- SendTimeout用於初始化OperationTimeout,它控制發送消息的整個交互(包括在請求 - 回復情況下接收回復消息)。 從CallbackContract方法發送回復消息時,此超時也適用。
- 打開和關閉通道時使用OpenTimeout和CloseTimeout(當沒有傳遞顯式超時值時)。
- 未使用ReceiveTimeout。
服務器端:
- 發送,打開和關閉超時與客戶端(用於回調)相同。
- ServiceFramework層使用ReceiveTimeout初始化會話空閑超時。
[編輯:一些代碼]也嘗試將此添加到您的服務配置
<behaviors>
<endpointBehaviors>
<behavior name="MyCallbackBehavior">
<callbackTimeouts transactionTimeout="00:00:10"/>
</behavior>
</endpointBehaviors>
<behaviors>
然后將行為添加到您的端點
<endpoint behaviorConfiguration="MyCallbackBehavior" />
好的我發現了錯誤......
我使用了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"/>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.