Bad Request/Underlying connection was closed problem solved

Posted by Marcus Hammarberg on 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.SystemNameService
m_wsService.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials
m_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.

Published by Marcus Hammarberg on Last updated