Bad Request/Underlying connection was closed problem solved

· May 31, 2007

In our project we have had great problems when debugging web services in Visual Studio. For about half of the the request on of two exceptions has been thrown:

  • System.Net.WebException: The request failed with HTTP status 400: Bad Request.
  • System.Net.Sockets.SocketException: The underlying connection was closed

After some looking into i found a solution and it was (as ever) quite easy. You simply have to set credentials on the web service as follows: Dim m_wsService wsSystemName.SystemNameService = New wsSystemName.SystemNameServicem_wsService.Credentials = System.Net.CredentialCache.DefaultNetworkCredentialsm_wsService.PreAuthenticate = True I have not observed this problem in C# so i presume that it is VB.NET related… or i might just be bad.

Twitter, Facebook