Answered by:
No connection could be made because the target machine actively refused it

Question
-
Hi all
In my asp.net application I try to connect to a web service hosted on a different server using the WebRequest Class.
The web service returns a string as a Response.
While doing so I get an Error: "System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it"
The code that I am using is below:WebRequest request = WebRequest.Create(url);
request.Credentials = CredentialCache.DefaultCredentials;
// Get the response.
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
// Display the status.
//Response.Write(response.StatusDescription);
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
responseFromServer = reader.ReadToEnd();
// Display the content.
//Response.Write(responseFromServer);
// Cleanup the streams and the response.
reader.Close();
dataStream.Close();
response.Close();The application is hosted on Windows 2003 server OS. The error persists even after disabling the Windows Fire Wall.
Kindly help in solving this error. Also i would like to know as to which port is used by the WEbRequest Class for sending the request and getting the response. Can we communicate through a port of our choice?
Waiting for your expert advice. Thanks in advance.
Wednesday, May 28, 2008 11:49 AM
Answers
-
8080 was just an example to answer your question about how to specify a port. Since you don't specify a port in your URL, you're getting port 80. You don't have to do any tracing to learn that.
- Proposed as answer by amitatbangalore Friday, May 30, 2008 5:12 AM
- Marked as answer by Jeff Cao - MSFTModerator Thursday, June 26, 2008 11:53 PM
Thursday, May 29, 2008 10:00 AMModerator
All replies
-
This exception usually means that there is nothing on the target machine listening on the port you're using. In other words, your service is not running.
You can use whatever port you want by specifying the port number in the URL, for instance, http://system.company.com:8080/default.aspx.
Wednesday, May 28, 2008 6:32 PMModerator -
Thnx John for the quick reply...
one more question: the port 8080 that you mentioned in the example is the port on the client machine or of the server??
Is there any way by which we can trace as to which port is being used to do the request?
waiting for repliess
Thursday, May 29, 2008 9:53 AM -
8080 was just an example to answer your question about how to specify a port. Since you don't specify a port in your URL, you're getting port 80. You don't have to do any tracing to learn that.
- Proposed as answer by amitatbangalore Friday, May 30, 2008 5:12 AM
- Marked as answer by Jeff Cao - MSFTModerator Thursday, June 26, 2008 11:53 PM
Thursday, May 29, 2008 10:00 AMModerator