开发者

Time out with a .NET WebRequest on IIS 6.0

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"]["t开发者_运维技巧ranslatedText"].ToString();

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

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.

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

Is there any setting on IIS that forbids web requests ?


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  
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜