2012-03-05 124 views
6

有沒有一種方法來設置一個tiemout在服務端,這樣,如果超過超時請求停止處理?我知道我可以一次申請了在客戶端,但並不能阻止服務器上的請求的處理。WCF服務超時

我已經嘗試添加下面的結合:

<basicHttpBinding> 
    <binding name="timeout" receiveTimeout="00:01:00" closeTimeout="00:01:00" openTimeout="00:01:00" sendTimeout="00:01:00" /> 
</basicHttpBinding> 

我也嘗試添加在對System.Web節點以下的(單獨和共同與上述):

<httpRuntime executionTimeout="60" /> <!-- timeout after 60 seconds --> 
+2

,你可以在終端的綁定配置中配置的超時與傳輸/通道超時大多鏈接,你問的是一個辦法時限服務處理 - 代碼無論多少通信時間都是必要的吧?例如你想設置你的WCF服務將中止處理操作,如果它需要超過2分鐘......這是你問的問題? – CSharpenter 2012-03-05 14:29:16

+0

@Csharpenter - 基本上是正確的。 – zimdanen 2012-03-05 14:36:26

回答

7

沒有內置(開箱)的方式來做到這一點。所有這一切,你可以設置超時被運送的設置有關。簡而言之,你必須自己去做。

另請參閱this answer有關限制WCF的執行時間。

+0

謝謝。可能需要等待稍後的項目,因爲我沒有時間爲當前項目獲得定製解決方案。 – zimdanen 2012-03-05 15:06:37

1

我們可以設置服務器端超時在「綁定」有:

Binding.ReceiveTimeout 

這是指定多久該服務可以從接收到的請求的開始等待超時消息被處理。這是服務器端設置。當你發送大郵件的服務和服務需要很長時間來處理,你就需要增加此設置。

http://msdn.microsoft.com/en-us/library/ms731361.aspx

使用這兩個超時要解決大多數超時問題。然而,當一個WCF服務在IIS/ASP.NET託管,其他設置也將控制請求的生命週期:

HttpRuntimeSection.ExecutionTimeout

<configuration> 
    <system.web> 
    <httpRuntime executionTimeout="600"/> 
    </system.web> 
</configuration> 
+0

查看我最近的修改 - 這似乎並沒有限制全服務電話從開始到結束的時間,這正是我想要做的。 – zimdanen 2012-03-05 14:45:30

+0

AFAIK,這是不正確的。有關'ReceiveTimeout'的更多信息,請參閱http://www.rauch.io/2015/06/25/all-wcf-timeouts-explained/ – 2016-03-08 14:44:39

0

是的,我可以處理它,你必須配置你的web.config文件它看起來像

<?xml version="1.0" encoding="UTF-8"?> 

<system.webServer> 
    <validation validateIntegratedModeConfiguration="false" /> 
    <modules runAllManagedModulesForAllRequests="true"> 
     <add name="DomainServiceModule" preCondition="managedHandler" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> 
    </modules> 
    <directoryBrowse enabled="false" /> 
</system.webServer> 

<system.web> 
    <httpModules> 
     <add name="DomainServiceModule" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> 
    </httpModules> 
    <compilation debug="true" targetFramework="4.0"> 
     <assemblies><add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 
     </assemblies> 
    </compilation> 
    <httpRuntime executionTimeout="36000"/> 
    <!--<sessionState mode="InProc" timeout="36000" />--> 
</system.web> 


<system.serviceModel> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> 

    <bindings> 
    <basicHttpBinding> 
     <binding name="Sbinding" maxReceivedMessageSize="1500000000" maxBufferSize="1500000000"> 
     <readerQuotas maxArrayLength="1500000000" maxStringContentLength="1500000000" /> 
     </binding> 
    </basicHttpBinding> 

    <webHttpBinding> 
     <binding name="Ubinding" maxBufferSize="1500000000" maxBufferPoolSize="1500000000" maxReceivedMessageSize="1500000000" transferMode="Streamed"> 
     <readerQuotas maxStringContentLength="1500000000" maxArrayLength="1500000000" maxBytesPerRead="1500000000" maxNameTableCharCount="1500000000" /> 
     </binding> 
    </webHttpBinding> 

    </bindings> 

    <behaviors> 
    <serviceBehaviors> 
      <behavior name="ClientUpload.Web.UploadService"> 
       <serviceMetadata httpGetEnabled="true" /> 
       <serviceDebug includeExceptionDetailInFaults="false" /> 
      </behavior> 

      <behavior name="ServiceBehaviour"> 
      <serviceMetadata httpGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="false" /> 
      </behavior> 
    </serviceBehaviors> 

    <endpointBehaviors> 
     <behavior name="web"> 
     <webHttp /> 
     </behavior> 
    </endpointBehaviors> 
    </behaviors> 


    <services> 
    <service behaviorConfiguration="ClientUpload.Web.UploadService" name="ClientUpload.Web.Services.UploadService"> 
     <endpoint address="" binding="basicHttpBinding" bindingConfiguration="Sbinding" contract="ClientUpload.Web.Services.IUploadService"> 
     <identity> 
      <dns value="localhost" /> 
     </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
    </service> 

    <service name="ClientUpload.Web.Services.RestService" behaviorConfiguration="ServiceBehaviour"> 
     <endpoint address="Rest" binding="webHttpBinding" contract="ClientUpload.Web.Services.IService1" behaviorConfiguration="web" bindingConfiguration="Ubinding"> 
     </endpoint> 
    </service> 
    </services>    


</system.serviceModel> 

- > - >

和你的客戶端ServiceReferences。ClientConfig文件看起來像

<configuration> 
<system.serviceModel> 

    <bindings> 
     <basicHttpBinding> 
      <binding name="BasicHttpBinding_IUploadService" closeTimeout="00:10:00" 
       openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" 
       maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"> 
       <security mode="None" /> 
      </binding> 
      <binding name="BasicHttpBinding_IUploadService1" closeTimeout="00:10:00" 
       openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" 
       maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"> 
       <security mode="None" /> 
      </binding> 

     </basicHttpBinding> 
    </bindings> 

    <!--<client> 
    <endpoint address="http://localhost/ClientUpload.Web_deploy/Services/UploadService.svc" 
     binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IUploadService" 
     contract="ServiceReference1.IUploadService" name="BasicHttpBinding_IUploadService" /> 
    </client>--> 


    <client> 
    <endpoint address="http://localhost:50503/Services/UploadService.svc" 
     binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IUploadService1" 
     contract="ServiceReference.ClientUpload.Web.Services.UploadService.IUploadService" 
     name="BasicHttpBinding_IUploadService1" /> 
    <endpoint address="http://localhost:50503/Services/UploadService.svc" 
     binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IUploadService" 
     contract="ServiceReference1.IUploadService" name="BasicHttpBinding_IUploadService" /> 
    </client> 

    <!--<client> 
    <endpoint address="http://10.223.211.37:81/ClientUpload/Services/UploadService.svc" 
     binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IUploadService" 
     contract="ServiceReference1.IUploadService" name="BasicHttpBinding_IUploadService" />   
    </client>-->  

</system.serviceModel>