[英]WCF service timeout
有沒有辦法在服務端設置tiemout,以便請求在超過超時時停止處理? 我知道我可以在客戶端計時請求,但這並不會停止在服務器上處理請求。
我嘗試添加以下綁定:
<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 -->
沒有內置(開箱即用)的方式來做到這一點。 您可以設置的所有超時都與傳輸設置有關。 簡而言之,你必須自己做。
另請參閱有關限制WCF執行時間的答案 。
您可以在服務綁定中進行設置,下面的鏈接顯示了在服務端和客戶端設置的值。
我們可以在“Binding”中設置服務器端超時:
Binding.ReceiveTimeout
這是超時,指定服務從接收請求開始到處理消息可等待的時間。 這是服務器端設置。 當您向服務發送大郵件並且服務需要很長時間來處理時,您需要增加此設置。
http://msdn.microsoft.com/en-us/library/ms731361.aspx
使用這兩個超時應該可以解決大多數超時問題。 但是,當在IIS / ASP.NET中托管WCF服務時,另一個設置也將控制請求的生命周期:
HttpRuntimeSection.ExecutionTimeout
<configuration>
<system.web>
<httpRuntime executionTimeout="600"/>
</system.web>
</configuration>
是的,我可以處理它你必須配置你的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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.