2010-02-10 62 views
4

我這裏有一個WCF雙工服務,該requierement是回調到客戶端應該有10秒的超時,爲此服務的我的web.config文件看起來像這樣:更改WCF默認的超時

 <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文件中的綁定與相同的超時值相同。

現在的效果是,如果客戶端向服務器發送請求,超時時間爲10秒。但另一方面,如果服務向客戶端發送回調,則超時爲1分鐘。這很奇怪...顯然超時正確設置在客戶端...但不是在服務...我如何更改服務的超時?

PS:我使用Visual Studio 2010和它與approbiate ASP.NET開發服務器10.0.0.0

回答

4

小結binding timeouts調試模式...

客戶端:

  • SendTimeout用於初始化OperationTimeout,它控制發送消息的整個交互(包括在請求 - 回覆情況下接收回復消息的 )。當從CallbackContract方法發送回覆消息時,此超時也適用於 。
  • 打開和關閉通道時(未傳遞顯式超時值時)使用OpenTimeout和CloseTimeout。
  • ReceiveTimeout未使用。

服務器端:

  • 發送,打開,並關閉超時相同的客戶端(回調)。
  • ReceiveTimeout由ServiceFramework層用於初始化會話空閒超時。

[編輯:一些代碼] 也嘗試添加這對您的服務配置

<behaviors> 
    <endpointBehaviors> 
     <behavior name="MyCallbackBehavior">  
     <callbackTimeouts transactionTimeout="00:00:10"/> 
     </behavior> 
    </endpointBehaviors> 
<behaviors> 

然後將行爲添加到您的端點

<endpoint behaviorConfiguration="MyCallbackBehavior" /> 
+0

當我的這種行爲客戶得到stucked當他試圖第一次調用服務的方法,其他超時(如代碼片段中所示)已經設置。是否有可能以某種方式WCF忽略我的設置並將所有TimeOut值設置回默認值? 有沒有一種方法來設置服務超時以編程方式我讀了一個關於這裏的線程,但解決方案對我來說不是很有吸引力 但是我在我的假設,當服務回調到客戶端..這是超時-duration與客戶端的超時設置無關嗎? – 2010-02-11 12:16:36

+0

這似乎是從https://msdn.microsoft.com/zh-CN/library/hh924831(v=vs.110).aspx逐字採取的。當您從在線來源複製逐字記錄時,您必須引用來源。我已經爲你修好了。 – 2015-06-30 08:37:28

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 =「配置的名稱」添加到端點聲明。

爲此,只爲你的信息我的工作配置是這樣的:

 <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"/>