Setting HTTP Header Authorization for Web Services

This is another post from the archives, brought back to life because there are still tons of StackOverflow links to it (7% of requests in January alone, crazy). This time it’s one from way back in 2006 about setting the Authorization header in a generated web proxy class. Like the last time, presented in it’s original form, aside from any updated links.

Begin wayback machine…

Original post date: October 3, 2006

On my most recent project we had to invoke some webMethods web services, which required basic authorization in order to be able to use the service. Wanting to abstract this away from any class that used this particular web service, we simply overrode the GetWebRequest method in the web service proxy and added the necessary info to the HTTP request header. Below is what it looked like:

The only problem is that when you re-generate your web service proxy you’ll lose the above method, so keep it around somewhere in case that happens (although you should just be able to get it back from the previous version in whatever source control repository you’re using).

…end wayback machine.

Featured Image: Some rights reserved by MysteryBee

One comment

  1. Vineeth says:

    Hi,
    I am trying to do this in VS 2008, can someone elaborate what the user Kosta has commented. This is for WIN CE application, so I have to use VS 2008 to achieve it, and in VS 2008 GetWebRequest(Uri uri) is not implemented so I cannot override it.

Leave a Reply

Your email address will not be published. Required fields are marked *