views:

371

answers:

1

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 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 ?

A: 

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
Jeff Widmer
Ok but my request is on Google Translate, so it should take someting like 1 second... Why would I need such a long timeout value ?My problem is not that the timeout is of only 100 seconds, but that the request lasts at least 100 seconds (and therefore the timeout is reached).
Julien
In that case use a tool like Fiddler to look at the headers getting sent in the development web server and then compare to those sent from IIS. There might be a header (for example user agent) that Google Translate wants to see.
Jeff Widmer