Thursday, July 1, 2010

The request failed with HTTP status 417: Expectation failed.

When using WebServices and calling some Web Methods, you may come across to this exception: 
"The request failed with HTTP status 417: Expectation failed."

Solution:


It is easy, here are two alternative ways:

1) We need to have this line of code before making any web requests.


1:
System.Net.ServicePointManager.Expect100Continue = false;


2) Add these lines to the application's configuration file (between <configuration> and </configuration>):

1:
2:
3:
4:
5:
<system.net>
 <settings>
  <servicePointManager expect100Continue="false" />
 </settings>
</system.net>


While this workaround is nice, I think a better long term solution is to upgrade/replace the proxy server to handle 100-continue calls.

So far in this short tip we've learned what is Expect 100, how it is caused and how to workaround this expectation.

ASP.NET AJAX - Update Panel Timeout

When using the asp:UpdatePanel server control for asyncronous communication with the web server the default timeout is 90 seconds. For some processes this may not be long enough.
For example, I am currently working on a reporting application and at the moment I have to query a table with over 36 million records. Some queries take longer than 90 seconds. But unfortunately I had trouble finding out how to extend this.
It turns out that this is a page-level setting. The asp:ScriptManager server control has a property namedAsyncPostBackTimeout. Set this value to the number of seconds you need to resonably run the process in question and you'll be fine.
<asp:scriptmanager id="scriptManager1" runat="server" enablepartialrendering="true" asyncpostbacktimeout="1000"></asp:ScriptManager>