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.