Click here to Skip to main content
15,885,278 members
Articles / Programming Languages / C#

The request failed with HTTP status 417: Expectation failed

Rate me:
Please Sign up or sign in to vote.
5.00/5 (11 votes)
15 Jul 2010CPOL2 min read 152.9K   9   9
The request failed with HTTP status 417: Expectation failed

When using WebServices and calling some Web Methods, you may come across this exception:

The request failed with HTTP status 417: Expectation failed.

When Expect 100-Continue property is set to true (this is actually set within part of the .NET Framework, which makes this a difficult problem to overcome. You have to override this in more than one place), this 417 error occurs when the proxy server doesn't support 100-Continue.

In the case of expect 100-Continue, the client will expect to receive a 100-Continue response from the server to indicate that the client should send the data to be posted. This mechanism allows clients to avoid sending large amounts of data over the network when the server, based on the request headers, intends to reject the request.

The Expect 100-Continue behavior is fully described in IETF RFC 2616 Section 10.1.1.

You can also read more about it in MSDN.

To work around this exception, you can do a simple thing: Disable expect 100 continue.

So you may ask how to disable expect 100 continue?

Warning: When you disable Expect 100-Continues and your application sends a large amount of data on the network, if for any reason the server rejects your request, you have to re-send the entire data again, this may cause some extra traffic in your network. Also multiple calls to a server will take longer, since each call will wait until the prior call's response is received.

It is easy. Here are two alternative ways:

  1. We need to have this line of code before making any web requests:
    C#
    System.Net.ServicePointManager.Expect100Continue = false; 
  2. Add these lines to the application's configuration file (between <configuration> and </configuration>):
    XML
    <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.

This article was originally posted at http://blog.mrt-web.com/feeds/posts/default

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionWorked great Pin
Member 236155412-Jun-15 4:07
Member 236155412-Jun-15 4:07 
QuestionExpect100Continue default value Pin
rafp612-Jun-14 7:44
rafp612-Jun-14 7:44 
GeneralMy vote of 5 Pin
erSitzt27-Dec-12 0:54
erSitzt27-Dec-12 0:54 
QuestionWebservice integration Exception Pin
d87manish31-Oct-12 21:27
d87manish31-Oct-12 21:27 
GeneralMy vote of 5 Pin
Nuno Agapito20-Sep-12 6:04
Nuno Agapito20-Sep-12 6:04 
GeneralRe: My vote of 5 Pin
mrt_doulaty20-Sep-12 6:11
mrt_doulaty20-Sep-12 6:11 
GeneralRe: My vote of 5 Pin
mrt_doulaty20-Sep-12 6:12
mrt_doulaty20-Sep-12 6:12 
Questionapplication's configuration file Pin
Ali Habib12-Sep-11 7:59
Ali Habib12-Sep-11 7:59 
AnswerRe: application's configuration file Pin
mrt_doulaty13-Sep-11 2:58
mrt_doulaty13-Sep-11 2:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.