sabato 2 luglio 2011

WCF Basic Authentication

In the past weeks I had to fight with a WebService that needs explicit Basic Authentication.
I had to write my program in C# 4.0, so the client that comes from wsdl follows WCF principles.
HTTP protocol assumes, for Basic Authentication, that the client must authenticate itself with a username and a password for each realm (see here).

For a Webservice client I thougth that I only had to set Authentication type to Basic and put Username and Password, but the server continued to reject my call, saying I had to provide a username. Using a proxy I discovered that in the http message the Header "Authentication" was missing: client does not set it automagically, as I tought it did. I did'nt check if this is the standard for WCF client or if it's a bug.

The problem can be solved adding "by hands" the header. For WCF Web Service you must act on the operation scope, not on the client itself. I found an example here, and I have to thank a lot who wrote it because he saved my night sleeping.

Italian original article here

0 commenti:

Posta un commento