zimdanen
zimdanen

Reputation: 5626

WCF service timeout

Is there a way to set a tiemout on the service side so that the request stops processing if it exceeds the timeout? I know I can time the request out on the client side, but that doesn't stop the processing of the request on the server.

I've tried adding 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've also tried adding the following in the system.web node (separately and together with the above):

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

Upvotes: 8

Views: 22641

Answers (4)

Dhaval Patel
Dhaval Patel

Reputation: 7591

yes i can handle it you have to configure your web.config file it's look 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 Side ServiceReferences.ClientConfig file 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>

Upvotes: 0

CSharpenter
CSharpenter

Reputation: 762

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

Please also see this answer about limiting WCF execution time.

Upvotes: 8

Min Min
Min Min

Reputation: 6218

We can set server side time out in "Binding" with:

Binding.ReceiveTimeout

This is the timeout that specifies how long the service can wait from the beginning of receiving a request until the message is processed. It’s server-side setting. When you send a large message to the service and the service needs long time to process, you would 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 a WCF service is hosted in IIS/ASP.NET, another setting would also control the lifetime of the request:

HttpRuntimeSection.ExecutionTimeout

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

Upvotes: 1

Matt Smucker
Matt Smucker

Reputation: 5234

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

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

Upvotes: 1

Related Questions