How to ensure the credentials for WebService using Windows
authentication
Answer / prasanna
Passing client credentials to a Web service using Windows
authentication
Sometimes a Web Service is under a configuration that
requires Windows Authentication. It is not a problem
for .NET, all you need to do is set your environment to
send the client credentials.
1. First Create a Reference to a Web Service:
To do that just go to the references of your project and
add a Web Reference. Type the URL of your web service. This
will find your Web Service Reference and you can update it.
This will generate the proxy code you need to access your
webservice.
If you try to call your webservice with a call like:
WebReference.MyService pService = new
WebReference.MyService ();
pService.doStuff("A", "B");
You’ll get a HTTP 404 forbidden access exception.
Now to send the user and password to call your service
write some code like the following:
WebReference.MyService pService = new
WebReference.MyService ();
pService.Credentials = new System.Net.NetworkCredential
("user", "password");
pService.doStuff("A", "B");
You can also send the domain name as part of the parameter
to the NetworkCredential class:
pService.Credentials = new System.Net.NetworkCredential
("user", "password","domain");
It will be even better to have your user and password not
in your code but in the configuration file for your
program. You can then use the AppSettings class to access
those properties.
| Is This Answer Correct ? | 2 Yes | 4 No |
How to update one of my table in database at 4pm every day how it is possible?
What is the difference between viewbag and viewdata in asp.net mvc?
What is MVVM design pattern?
What are Model Binders in ASP.Net MVC?
How to add 'ASPNET.mdf' file into server explorer in visual studio 2005?
Do you know about the new features in asp.net mvc 4 (asp.net mvc4)?
Is it possible to unit test an mvc application without running the controllers in an asp.net process?
Can you write a class without specifying namespace? Which namespace does it belong to by default?
Can I set the unlimited length for "maxjsonlength" property in config?
What is asp net framework?
What is the 'page life cycle' of an ASP.NET MVC?
What is boxing and unboxing?