簡體   English   中英

WCF服務,如何增加超時?

[英]WCF Service , how to increase the timeout?

可能看起來像一個愚蠢的問題,但WCF中的所有內容似乎都比asmx復雜得多,我怎樣才能增加svc服務的超時?

這是我到目前為止:

<bindings>
      <basicHttpBinding>
        <binding name="IncreasedTimeout" 
          openTimeout="12:00:00" 
          receiveTimeout="12:00:00" closeTimeout="12:00:00"
          sendTimeout="12:00:00">
        </binding>
      </basicHttpBinding>
</bindings>

然后我的端點映射如下:

<endpoint address="" 
  binding="basicHttpBinding" bindingConfiguration="IncreasedTimeout"
             contract="ServiceLibrary.IDownloads">
             <identity>
                <dns value="localhost" />
             </identity>
          </endpoint>

我得到的確切錯誤:

在00:00:59.9990000之后等待回復時,請求通道超時。 增加傳遞給Request的調用的超時值或增加Binding上的SendTimeout值。 分配給此操作的時間可能是較長超時的一部分。

在WCF測試客戶端中,有一個配置圖標,其中包含我的服務的運行時配置:

你可以看到它與我為它設定的值不一樣嗎? 我究竟做錯了什么?

<bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IDownloads" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    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="">
                            <extendedProtectionPolicy policyEnforcement="Never" />
                        </transport>
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>

在綁定配置中,您可以調整四個超時值:

<bindings>
  <basicHttpBinding>
    <binding name="IncreasedTimeout"
             sendTimeout="00:25:00">
    </binding>
  </basicHttpBinding>

最重要的是sendTimeout ,它表示客戶端等待WCF服務響應的時間。 您可以在設置中指定hours:minutes:seconds - 在我的示例中,我將超時設置為25分鍾。

名稱暗示的openTimeout是您打開與WCF服務的連接時願意等待的時間。 類似地, closeTimeout是您關閉在拋出異常之前等待的連接( closeTimeout客戶端代理)的時間。

receiveTimeout有點像在鏡子sendTimeout -而發送超時的時候,你會等待來自服務器的響應量, receiveTimeout是的時候,你會給你的客戶接受和處理量來自服務器的響應。

如果您來回發送“正常”消息,兩者都可能非常短 - 尤其是receiveTimeout ,因為接收SOAP消息,解密,檢查和反序列化消息幾乎不需要時間。 故事與流式傳輸不同 - 在這種情況下,您可能需要更多時間在客戶端上實際完成從服務器返回的流的“下載”。

還有openTimeout,receiveTimeout和closeTimeout。 有關綁定MSDN文檔為您提供了有關這些內容的更多信息。

為了嚴格控制WCF的所有復雜性,我強烈建議您購買Michele Leroux Bustamante撰寫的“ 學習WCF ”一書:

學習WCF http://ecx.images-amazon.com/images/I/51GNuqUJq%2BL._BO2,204,203,200_PIsitb-sticker-arrow-click,TopRight,35,-76_AA240_SH20_OU01_.jpg

你還花了一些時間看她的15部分“ WCF Top to Bottom ”截屏系列 - 強烈推薦!

對於更高級的主題,我建議您查看Juwal Lowy的編程WCF服務手冊。

編程WCF http://ecx.images-amazon.com/images/I/41odWcLoGAL._BO2,204,203,200_PIsitb-sticker-arrow-click,TopRight,35,-76_AA240_SH20_OU01_.jpg

需要在客戶端級別設置超時配置,因此我在web.config中設置的配置無效,WCF測試工具有自己的配置,您需要設置超時。

最好的方法是在代碼中更改所需的任何設置。

看看下面的例子:

using(WCFServiceClient client = new WCFServiceClient ())
{ 
    client.Endpoint.Binding.SendTimeout = new TimeSpan(0, 1, 30);
}

最近得到了同樣的錯誤但是能夠通過確保關閉每個wcf客戶端調用來修復它。 例如。

WCFServiceClient client = new WCFServiceClient ();
//More codes here
// Always close the client.
client.Close();

要么

using(WCFServiceClient client = new WCFServiceClient ())
{ 
    //More codes here 
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM