Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase the timeout values for a WCF service in a dot net core 2.1 project

I am posting this because I was unable to find any place on Stack Overflow that addresses this issue for a .Net-Core project utilizing WCF by adding the service reference through Connected Services.

My issue was that I was facing client side timeouts because of long running operation requests.

So, how does one increase the timeout values for the wcf client objects since .Net-Core no longer uses the web config to store the configuration values for the WCF service references? (Please see my provided answer)

like image 997
Ryan Wilson Avatar asked Oct 29 '18 13:10

Ryan Wilson


People also ask

How do you increase timeout in WCF Test client?

In the WCF Test Client you will find a node called Config File beneath your service. Right-click this and select Edit with SvcConfigEditor to increase timeout on the client.

How can I increase my response time in WCF?

Under the Tools menu in Visual Studio 2008 (or 2005 if you have the right WCF stuff installed) there is an options called 'WCF Service Configuration Editor'. From there you can change the binding options for both the client and the services, one of these options will be for time-outs.

What is the default timeout for WCF service?

The most common default timeout values within Archiver are: 2 min for querying the Microsoft SQL Server. 5 min for WCF connections (This is used heavily for internal communication between GFI Archiver's own modules).


1 Answers

Under Connected Services in Solution Explorer, after adding a WCF service, a few files are generated for that service. You should see a folder with the name you gave the WCF service reference and under that a Getting Started, ConnectedService.json and a Reference.cs file.

To increase any of the client service object's timeout values, open Reference.cs and locate method: GetBindingForEndpoint

Inside this method you should see something like this:

if ((endpointConfiguration == EndpointConfiguration.BasicHttpBinding_IYourService))
            {
                System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
                result.MaxBufferSize = int.MaxValue;
                result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
                result.MaxReceivedMessageSize = int.MaxValue;
                result.AllowCookies = true;
                //Here's where you can set the timeout values
                result.SendTimeout = new System.TimeSpan(0, 5, 0);
                result.ReceiveTimeout = new System.TimeSpan(0, 5, 0);

                return result;
            }

Just use result. and the timeout you want to increase like SendTimeout, ReceiveTimeout, etc. and set it to a new TimeSpan with the desired timeout value.

I hope this proves to be a useful post to someone.

like image 83
Ryan Wilson Avatar answered Oct 19 '22 22:10

Ryan Wilson