来自 Windows 服务和服务器的 WebRequest 超时
WebRequest timeout from Windows Service and Server
目前我们有一个 Windows 服务来处理来自 RabbitMQ 的消息。它通过使用对 URi 的 Web 请求来完成此操作。然后我们读取响应,如果成功则从那里继续。
处理消息方法
//Deserialze the response
PMResponse res = (PMResponse)ser.ReadObject(GetResponse(addr + paramArgs));
GetResponse 方法
private static MemoryStream GetResponse(string URi)
{
// Create a request using a URL that can receive a post.
WebRequest request = WebRequest.Create(URi);
// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.
string postData = "";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream();
// 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();
// Get the stream containing content returned by the server.
dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
// Display the content.
//Console.WriteLine(responseFromServer);
MemoryStream mStrm = new MemoryStream(Encoding.UTF8.GetBytes(responseFromServer));
reader.Close();
dataStream.Close();
return mStrm;
}
该服务安装在我们的一台服务器上,上周不知何故,该应用程序停止处理消息。
当我们在网络浏览器中打开参数化 URL 时,我们用来处理 SMS 消息的网络服务工作正常。
该服务也适用于我的本地计算机。但是,当作为服务或测试控制台应用程序部署在服务器上时,操作会超时。
您认为存在哪些问题?该代码有效,只是不在此服务器上。
回答以节省人们的时间:
"The problem is resolved, the company we use for sending the SMS restarted their servers and it worked fine. Many man hours wasted on this before it even got to me hah. Thanks for your time guys."
目前我们有一个 Windows 服务来处理来自 RabbitMQ 的消息。它通过使用对 URi 的 Web 请求来完成此操作。然后我们读取响应,如果成功则从那里继续。
处理消息方法
//Deserialze the response
PMResponse res = (PMResponse)ser.ReadObject(GetResponse(addr + paramArgs));
GetResponse 方法
private static MemoryStream GetResponse(string URi)
{
// Create a request using a URL that can receive a post.
WebRequest request = WebRequest.Create(URi);
// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.
string postData = "";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream();
// 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();
// Get the stream containing content returned by the server.
dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
// Display the content.
//Console.WriteLine(responseFromServer);
MemoryStream mStrm = new MemoryStream(Encoding.UTF8.GetBytes(responseFromServer));
reader.Close();
dataStream.Close();
return mStrm;
}
该服务安装在我们的一台服务器上,上周不知何故,该应用程序停止处理消息。
当我们在网络浏览器中打开参数化 URL 时,我们用来处理 SMS 消息的网络服务工作正常。
该服务也适用于我的本地计算机。但是,当作为服务或测试控制台应用程序部署在服务器上时,操作会超时。
您认为存在哪些问题?该代码有效,只是不在此服务器上。
回答以节省人们的时间: "The problem is resolved, the company we use for sending the SMS restarted their servers and it worked fine. Many man hours wasted on this before it even got to me hah. Thanks for your time guys."