C# IIS 6.0上的.NET WebRequest超时

C# IIS 6.0上的.NET WebRequest超时,c#,.net,asp.net,iis-6,C#,.net,Asp.net,Iis 6,在我的ASP.NET2.0Web服务中,我试图访问GoogleAPI来翻译一些文本。以下代码实现了此功能: string result = ""; // create the web request to the Google Translate REST interface System.Net.WebRequest oRequest = System.Net.WebRequest.Create("http://ajax.googleapis.com/ajax/services/langua

在我的ASP.NET2.0Web服务中,我试图访问GoogleAPI来翻译一些文本。以下代码实现了此功能:

string result = "";

// create the web request to the Google Translate REST interface
System.Net.WebRequest oRequest = System.Net.WebRequest.Create("http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q="
    + System.Web.HttpUtility.UrlEncode("Text to translate") + "&langpair=" + "en" + "%7C" + "fr");

// make the web call
System.Net.WebResponse oResponse = oRequest.GetResponse();

// grab the response stream
System.IO.StreamReader oReader = new System.IO.StreamReader(oResponse.GetResponseStream());

// put the whole response in a string
string sContent = oReader.ReadToEnd();

// parse the string into the litJSON simple object model
JsonData oData = JsonMapper.ToObject(sContent);

// write out the translated text
result = oData["responseData"]["translatedText"].ToString();
JsonData来自DLL LitJson->

只要我在ASP.NET开发服务器上,这就可以正常工作。但是,当我将Web服务放入IIS 6.0服务器时,我发现客户端中的操作超时错误

对于System.Net.WebClient,我会得到相同的超时


IIS上是否有任何禁止web请求的设置?

在开发web服务器中,超时设置为无限。当您移动到IIS6时,超时值将得到尊重,然后您的请求将比默认值花费更长的时间,然后超时。在oRequest对象System.Net.HttpWebRequest对象上,可以通过设置timeout属性来更改超时值。默认超时为100000毫秒100秒

oRequest.Timeout = 300000;  //300,000 milliseconds or 300 seconds or 5 minutes  

如果您还没有,请检查是否可以从IIS 6.0服务器访问/ping。好的,但我的请求是在Google Translate上,所以需要1秒左右的时间。。。为什么我需要这么长的超时值?我的问题不是超时时间只有100秒,而是请求至少持续100秒,因此达到了超时时间。在这种情况下,请使用Fiddler之类的工具查看在开发web服务器中发送的头,然后与从IIS发送的头进行比较。Google Translate可能希望看到一个标题,例如用户代理。