WCF Service Timeout

Is there a way to set tiemout on the service side so that the request stops processing if it exceeds the timeout? I know that I can request time on the client side, but this does not stop processing the request on the server.

I tried to add the following binding:

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

I also tried adding the following to system.web node (separately and together with the above):

 <httpRuntime executionTimeout="60" /> <!-- timeout after 60 seconds --> 
+6
source share
4 answers

There is no built-in (out of the box) way to do this. All timeouts that you can set are related to the transport settings. In short, you must do it yourself.

Also see this answer on WCF runtime limitation.

+7
source

You can set this in your service bindings, the link below shows the values ​​set on the service side, as well as on the client side.

http://geekswithblogs.net/smyers/archive/2011/10/05/wcf-service-message-timeouts-size-limits-tips-and-tricks.aspx

+1
source

We can set the server-side time in "Binding" with:

 Binding.ReceiveTimeout 

This is a timeout that determines how long the service can wait from the start of receiving the request until the message has been processed. Its configuration on the server side. When you send a large message to the service, and the service takes a long time to process, you will need to increase this setting.

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

Using these two timeouts should solve most timeout problems. However, when the WCF service is hosted in IIS / ASP.NET, another parameter will also control the request lifetime:

HttpRuntimeSection.ExecutionTimeout

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

yes, I can handle this, you need to configure your web.config file so that it looks like

 <?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> 

-> β†’

And your client file ServiceReferences.ClientConfig looks like

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

0
source

Source: https://habr.com/ru/post/910000/


All Articles