I have very weird issue.
I have method that called by wcf that hosted by Windows service , while the method try to do GetRequestStream() we get back an exception “Unable to connect to the remote server“
string strXMLServer = "https://xxxx.webex.com/WBXService/XMLService";
WebRequest request = WebRequest.Create(strXMLServer);
// Set the Method property of the request to POST.
request.Method = "POST";
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
string strXML = XMLmanager.createXML(User, Password, requestType, sessionKey);
byte[] byteArray = Encoding.UTF8.GetBytes(strXML);
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream(); //<--- here the exception!!
// Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close();
// Get the response.
WebResponse response = request.GetResponse();
The Weird thing is that when I try to run this application as a stanalone ( console application) I have no problem and get no error! the Exception appear only if I call the method by the WCF !
Sound like you have a similar situation to this SO question. Check the account your Windows Service is running under, it most likely does have not access to network resources.