在IIS 6.0上使用.NET WebRequest超时 [英] Time out with a .NET WebRequest on IIS 6.0

查看:75
本文介绍了在IIS 6.0上使用.NET WebRequest超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的ASP.NET 2.0 Web服务中,我试图访问Google API来翻译一些文本.以下代码可以正确执行此操作:

In my ASP.NET 2.0 web service I am trying to access Google API to translate some texts. Following code does this right :

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-> http://litjson.sourceforge.net )

(JsonData is from the DLL LitJson --> http://litjson.sourceforge.net)

只要我在ASP.NET开发服务器上,此方法就可以正常工作.但是,一旦将Web服务放到IIS 6.0服务器上,我的客户端就会收到操作已超时"错误.

This works just fine as long as I am on the ASP.NET development server. But as soon as I put my Web service to my IIS 6.0 server, I get "The operation has timed out" errors in my client.

使用System.Net.WebClient,我得到相同的超时时间.

With a System.Net.WebClient I get the same timeout.

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

Is there any setting on IIS that forbids web requests ?

推荐答案

在开发Web服务器中,超时设置为无限.当您移至IIS6时,超时值将得到考虑,然后您的请求将花费比默认时间更长的时间,然后超时.在oRequest对象(System.Net.HttpWebRequest对象)上,可以通过设置Timeout属性来更改超时值.默认超时为100,000毫秒(100秒).

In the development web server the timeout is set to infinite. When you move to IIS6 timeout values are respected and then your request takes longer than the default and then times out. On your oRequest object (System.Net.HttpWebRequest object) you can change the timeout value by setting the Timeout property. The default timeout is 100,000 milliseconds (100 seconds).

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

这篇关于在IIS 6.0上使用.NET WebRequest超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆