Debugging .NET Web Services

I’ve been spending a lot of time lately debugging web services and I’ve been getting frustrated with the client timing out on me, so I finally buckled down and figured out how to prevent it.

Web Services consist of two parts – a client and a server.  The client is implemented as a class derived from System.Web.Services.Protocols.WebClientProtocol, e.g. through SoapHttpClientProtocol or HttpWebClientProtocol.

When a client calls a method on a web service, an asynchronous message is sent to the web service and the client waits for it to complete.  The client doesn’t wait forever, however.  The default timeout is 100 seconds (100,000 ms).  To change this, you must set the Timeout property on the web service client object, like so:

MyWebService client = new MyWebService();
client.Timeout = System.Threading.Timeout.Infinite;

The Timeout property contains a value representing the number of milliseconds to wait for calls to return before throwing a System.Net.WebException exception.  To prevent it from timing out altogether, specify either -1 or System.Threading.Timeout.Infinite.

Reources