简体   繁体   中英

Increase C# class library(DLL) Timeout calling wcf service

I have a class library on which I am calling WCF service. This service takes around 3 minutes to complete. I am using Windows Forms and I added executionTimeout to the App.Config in the httpRuntime element. Still, it does not wait till it completes the transaction. How can I put a longer waiting period for the call?

I have added the code below in App.Config of my Windows Forms application

    <system.web>
   <compilation debug="false"/>
    <httpRuntime executionTimeout="360" />  
  </system.web>

I call my service in the button click like below.

Registration rObj = new Registration("http://x.x.x.x:1010/Service.svc");
RegInfo sObj = rObj.ValidateRegistration("1234");
MessageBox.Show(sObj.bIsRegistered.ToString());

But the above call TimesOut when the request takes a bit long to respond.

You need to set timeout on WCF application as well as Windows forms Application

1) WCF application : please add below changes in web.config

=> First Change

<bindings>
   <basicHttpBinding>
        <binding name="BasicHttpsBindingConfig" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"
         receiveTimeout="00:10:00" sendTimeout="00:10:00">
    <readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647"/>
        </binding>
   </basicHttpBinding>
</bindings>

=> Second Change: Increase time out in web.config

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

2) Windows form Application example:

public static void Main()  
        {  
            Uri baseAddress = new Uri("http://localhost/MyServer/MyService");  

            try  
            {  
                ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService));  

                WSHttpBinding binding = new WSHttpBinding();  
                binding.OpenTimeout = new TimeSpan(0, 10, 0);  
                binding.CloseTimeout = new TimeSpan(0, 10, 0);  
                binding.SendTimeout = new TimeSpan(0, 10, 0);  
                binding.ReceiveTimeout = new TimeSpan(0, 10, 0);  

                serviceHost.AddServiceEndpoint("ICalculator", binding, baseAddress);  
                serviceHost.Open();  

                // The service can now be accessed.  
                Console.WriteLine("The service is ready.");  
                Console.WriteLine("Press <ENTER> to terminate service.");  
                Console.WriteLine();  
                Console.ReadLine();  

            }  
            catch (CommunicationException ex)  
            {  
                // Handle exception ...  
            }  
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM