Question

setup timeout for external request

Hi everyone

Can i increase the timeout  ? for an external request  :

	var request_user = WebRequest.Create(XMLUrl) as HttpWebRequest;
	request_user.Credentials = new System.Net.NetworkCredential(XMLUserParameter, XMLPasswordParameter);
	var response_user = request_user.GetResponse();

is an XML file 40mb, it will be increase the size ,

 

Some times the request works but not ever 

if i can, what i should to change it

 

 

Like 0

Like

4 comments
Best reply

Hello Carlos,

In your code sample you posted, you're using a HttpWebRequest for the call to the external service. For WebRequest, you can set the timeout like this:

var request_user = WebRequest.Create(XMLUrl) as HttpWebRequest;
request_user.Timeout = 500000; // set timeout here
request_user.Credentials = new System.Net.NetworkCredential(XMLUserParameter, XMLPasswordParameter);
var response_user = request_user.GetResponse();

Note, the Timeout property is in milliseconds - I believe the default is 100000 ms, or 100 seconds)

Ryan

Hello Carlos,

In your code sample you posted, you're using a HttpWebRequest for the call to the external service. For WebRequest, you can set the timeout like this:

var request_user = WebRequest.Create(XMLUrl) as HttpWebRequest;
request_user.Timeout = 500000; // set timeout here
request_user.Credentials = new System.Net.NetworkCredential(XMLUserParameter, XMLPasswordParameter);
var response_user = request_user.GetResponse();

Note, the Timeout property is in milliseconds - I believe the default is 100000 ms, or 100 seconds)

Ryan

thanks Ryan Farley,

 

So i don't need to configure anything in the iis or .config files?

Carlos Alberto Arce Ortuño,

 

Yes, please follow Ryan's answer it should work properly.

 

Best Regards,

 

Bogdan L.

Ryan Farley,

 

That's amazing! 

 

Thanks for your reply!

 

Regards,

 

Bogdan L.

Show all comments