尝试GetRequestStream()时无法连接到远程服务器()
问题描述:
我有一个很奇怪的问题。尝试GetRequestStream()时无法连接到远程服务器()
我有一个通过WCF称为通过Windows服务托管方法,而该方法尝试做GetRequestStream(),我们得到一个异常“无法连接到远程服务器”
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();
奇怪的是,当我尝试运行这个应用程序作为stanalone(控制台应用程序),我没有问题,并没有错误!只有在我通过WCF调用方法时才会出现异常!
在本地系统下运行的Windows服务 – MoShe 2012-03-19 18:16:59
在这种情况下,您需要使用作为具有适当访问权限的域帐户进行HTTP调用或作为机器帐户(通常是计算机名称)所在的网络服务该域并具有适当的访问权限。 – 2012-03-19 18:43:02