The underlying connection was closed: Unable to connect to the remote server.

March 1, 2007

we were in the technical problem since since last couple of the days. we googled it a lot , however after all we have done it today :). special thanks to Jigar Pandit for the same.

Problem:
Web service call is working fine in our local system. however when we installed middle-tier service (which contains dll of web-service call) on remote server. it started giving “The underlying connection was closed: Unable to connect to the remote server.” Error. 

Description
This problem may occur when one or more of the following conditions are true:

A network outage occurs.
A proxy server blocks the HTTP request.
A Domain Name System (DNS) problem occurs.
A network authentication problem occurs.

Resolution

To resolve this problem, make sure that the proxy settings are correct. To do this, use the following techniques:

Use the static WebProxy.GetDefaultProxy method. For more information, visit the following Microsoft Web site:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemnetwebproxyclassgetdefaultproxytopic.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemnetwebproxyclassgetdefaultproxytopic.asp)

Define a <proxy> element in the application configuration files. For more information, visit the following Microsoft Web site:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/gngrfproxyelement.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/gngrfproxyelement.asp)

Configure the .NET client to use HTTP 1.0 by changing the HttpWebRequest.ProtocolVersion property. For more information, visit the following Microsoft Web site:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemnethttpwebrequestclassprotocolversiontopic.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemnethttpwebrequestclassprotocolversiontopic.asp)

Note By default, the .NET Framework uses HTTP 1.1.

Out of this 3 option, first one works for us.

Reference Taken From
http://support.microsoft.com/kb/915599/en-us