Increase WCF Service Call Timeout in ASP.NET Web API Project

A few months ago, I ran into a situation where I had to increase the timeout for a WCF service call, that my ASP.NET Web API was making. It wasn't as straightforward as just adding configuration to a config file, like you would do with a WCF service. You actually have to do it in code. The answers to the stackoverflow question listed below, helped a lot in figuring out a solution for it.

Link: How to increase the timeout values for a WCF service in a dot net core 2.1 project – Stack Overflow

In your Web API code, you can create a partial class for the WCF client you are trying to call. In that class, you should be able to get to the Endpoint object. This object allows you get to the WCF bindings where you can set the timeout values. Then you can do something similar to the code I have below to set the timeouts.

TimeSpan timeSpan = new TimeSpan(hours: 0, minutes: 0, seconds: timeoutInSeconds);
Endpoint.Binding.CloseTimeout = timeSpan;
Endpoint.Binding.OpenTimeout = timeSpan;
Endpoint.Binding.ReceiveTimeout = timeSpan;
Endpoint.Binding.SendTimeout = timeSpan;

Tags: #AspDotNet #AspDotNetWebApi #WCF

Discuss... or leave a comment below.