{"id":5283,"date":"2005-02-01T23:00:00","date_gmt":"2005-02-01T23:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/buckh\/2005\/02\/01\/timeouts-on-the-httpwebrequest-and-thus-soap-proxies\/"},"modified":"2005-02-01T23:00:00","modified_gmt":"2005-02-01T23:00:00","slug":"timeouts-on-the-httpwebrequest-and-thus-soap-proxies","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/buckh\/timeouts-on-the-httpwebrequest-and-thus-soap-proxies\/","title":{"rendered":"Timeouts on the HttpWebRequest (and thus SOAP proxies)"},"content":{"rendered":"<p>Last summer I wrote <a href=\"http:\/\/blogs.msdn.com\/buckh\/archive\/2004\/08\/13\/214364.aspx\">several posts on using HttpWebRequest and SOAP proxies<\/a>.&nbsp; Recently I was working on code that needed to handle requests that could take a really long time for the server to process.&nbsp; The client would give up and close the network connection long before the request completed.<\/p>\n<p>The code had tried to control that using the <a href=\"http:\/\/msdn2.microsoft.com\/library\/cy9yd268.aspx\">HttpWebRequest.Timeout property<\/a>.&nbsp; That helped, but it didn&#8217;t solve the problem.&nbsp; Without changing the Timeout property, the client gave up after 100 seconds, which is the default value for that property as stated in the docs.&nbsp; The Timeout property was set to infinite, but the client gave up after&nbsp;five minutes.&nbsp; Below is the doc for the Timeout property.<\/p>\n<blockquote>\n<p><span class=\"majorLabel\"><span class=\"majorLabel\">Return Value<\/span> <\/span><\/p>\n<div class=\"content\">\n<div class=\"returnValue\">\n<p>The number of milliseconds to wait before the request times out. The default is 100000 milliseconds (100 seconds).<\/p>\n<p>Remarks <\/p>\n<\/div>\n<\/div>\n<div class=\"remarks\">\n<p><span class=\"codeEntityReference\"><a href=\"http:\/\/msdn2.microsoft.com\/library\/cy9yd268.aspx\">Timeout<\/a><\/span> is the number of milliseconds that a synchronous request made with the <span class=\"codeEntityReference\"><a href=\"http:\/\/msdn2.microsoft.com\/library\/9b2a9x7d.aspx\">GetResponse<\/a><\/span> method waits for a response, and the <span class=\"codeEntityReference\"><a href=\"http:\/\/msdn2.microsoft.com\/library\/d4cek6cc.aspx\">GetRequestStream<\/a><\/span> method waits for a stream. If the resource is not returned within the time-out period, the request throws a <span class=\"codeEntityReference\"><a href=\"http:\/\/msdn2.microsoft.com\/library\/ztey1y5b.aspx\">WebException<\/a><\/span> with the <span class=\"codeEntityReference\"><a href=\"http:\/\/msdn2.microsoft.com\/library\/9y38296e.aspx\">Status<\/a><\/span> property set to <span class=\"codeEntityReference\"><a href=\"http:\/\/msdn2.microsoft.com\/library\/tf6dzhcf.aspx\">Timeout<\/a><\/span>.<\/p>\n<p>The <span class=\"codeEntityReference\"><a href=\"http:\/\/msdn2.microsoft.com\/library\/cy9yd268.aspx\">Timeout<\/a><\/span> property has no effect on asynchronous requests made with the <span class=\"codeEntityReference\"><a href=\"http:\/\/msdn2.microsoft.com\/library\/21k58ta7.aspx\">BeginGetResponse<\/a><\/span> or <span class=\"codeEntityReference\"><a href=\"http:\/\/msdn2.microsoft.com\/library\/dedz1835.aspx\">BeginGetRequestStream<\/a><\/span> methods.<\/p>\n<div class=\"content\"><span class=\"alert\">Caution <\/span>In the case of asynchronous requests, it is the responsibility of the client application to implement its own timeout mechanism. Refer to the example in the <span class=\"codeEntityReference\"><a href=\"http:\/\/msdn2.microsoft.com\/library\/21k58ta7.aspx\">BeginGetResponse<\/a><\/span> method.<\/div>\n<p>To specify the amount of time to wait before a read or write operation times out, use the <span class=\"codeEntityReference\"><a href=\"http:\/\/msdn2.microsoft.com\/library\/b1w9c0s4.aspx\">ReadWriteTimeout<\/a><\/span> property.<\/p>\n<\/div>\n<\/blockquote>\n<p>At the end of that, notice that they mention another timeout value, the <a href=\"http:\/\/msdn2.microsoft.com\/library\/b1w9c0s4.aspx\">HttpWebRequest.ReadWriteTimeout property<\/a>.&nbsp; Here&#8217;s the doc for that.<\/p>\n<blockquote>\n<p><span class=\"majorLabel\">Return Value<\/span> <\/p>\n<\/blockquote>\n<div class=\"returnValue\">\n<blockquote>\n<p>The number of milliseconds before the writing or reading times out. Its default value is 300000 milliseconds (5 minutes).<\/p>\n<p><span class=\"majorLabel\">Remarks<\/span> <\/p>\n<\/blockquote>\n<div class=\"remarks\">\n<blockquote>\n<p>The <span class=\"codeEntityReference\"><a href=\"http:\/\/msdn2.microsoft.com\/library\/b1w9c0s4.aspx\"><font color=\"#002c99\">ReadWriteTimeout<\/font><\/a><\/span> is used when writing to the stream returned by <span class=\"codeEntityReference\"><a href=\"http:\/\/msdn2.microsoft.com\/library\/d4cek6cc.aspx\"><font color=\"#002c99\">GetRequestStream<\/font><\/a><\/span> or reading from the stream returned by <span class=\"codeEntityReference\"><a href=\"http:\/\/msdn2.microsoft.com\/library\/e1ax3cw0.aspx\"><font color=\"#002c99\">GetResponseStream<\/font><\/a><\/span>.<\/p>\n<p>Specifically, the <span class=\"codeEntityReference\"><a href=\"http:\/\/msdn2.microsoft.com\/library\/b1w9c0s4.aspx\"><font color=\"#002c99\">ReadWriteTimeout<\/font><\/a><\/span> property controls the time-out for the <span class=\"codeEntityReference\"><a href=\"http:\/\/msdn2.microsoft.com\/library\/29tb55d8.aspx\"><font color=\"#002c99\">Read<\/font><\/a><\/span> method, which is used to read the stream returned by the <span class=\"codeEntityReference\"><a href=\"http:\/\/msdn2.microsoft.com\/library\/e1ax3cw0.aspx\"><font color=\"#002c99\">GetResponseStream<\/font><\/a><\/span> method, and for the <span class=\"codeEntityReference\"><a href=\"http:\/\/msdn2.microsoft.com\/library\/xsfehx6h.aspx\"><font color=\"#002c99\">Write<\/font><\/a><\/span> method, which is used to write to the stream returned by <span class=\"codeEntityReference\"><a href=\"http:\/\/msdn2.microsoft.com\/library\/d4cek6cc.aspx\"><font color=\"#002c99\">GetRequestStream<\/font><\/a><\/span> method.<\/p>\n<p>To specify the amount of time to wait for the request to complete, use the <span class=\"codeEntityReference\"><a href=\"http:\/\/msdn2.microsoft.com\/library\/cy9yd268.aspx\"><font color=\"#002c99\">Timeout<\/font><\/a><\/span> property.<\/p>\n<\/blockquote>\n<p>Well, there&#8217;s&nbsp;the five minute timeout.&nbsp; If you want to wait for a long request, which is greater than five minutes for the HttpWebRequest, you need to set both properties.&nbsp; Using the information in the <a href=\"http:\/\/blogs.msdn.com\/buckh\/archive\/2004\/08\/13\/214364.aspx\">post from the summer<\/a>, you can add code to your override of <a href=\"http:\/\/msdn.microsoft.com\/library\/default.asp?url=\/library\/en-us\/cpref\/html\/frlrfsystemwebservicesprotocolshttpwebclientprotocolclasstopic.asp\">GetWebRequest()<\/a> in your&nbsp;SOAP&nbsp;proxy&nbsp;to set the timeout to an hour, for example,&nbsp;using <font face=\"Courier New\">request.Timeout = 3600 * 1000<\/font> and <font face=\"Courier New\">request.ReadWriteTimeout = 3600 * 1000<\/font>.<\/p>\n<p>You may also notice that the Timeout property doesn&#8217;t apply to asynchronous calls that use the Begin\/End call pattern.&nbsp; For those, only the ReadWriteTimeout applies.<\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Last summer I wrote several posts on using HttpWebRequest and SOAP proxies.&nbsp; Recently I was working on code that needed to handle requests that could take a really long time for the server to process.&nbsp; The client would give up and close the network connection long before the request completed. The code had tried to [&hellip;]<\/p>\n","protected":false},"author":94,"featured_media":10268,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[2],"class_list":["post-5283","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-c"],"acf":[],"blog_post_summary":"<p>Last summer I wrote several posts on using HttpWebRequest and SOAP proxies.&nbsp; Recently I was working on code that needed to handle requests that could take a really long time for the server to process.&nbsp; The client would give up and close the network connection long before the request completed. The code had tried to [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/posts\/5283","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/users\/94"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/comments?post=5283"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/posts\/5283\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/media\/10268"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/media?parent=5283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/categories?post=5283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/tags?post=5283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}