How to ensure the credentials for WebService using Windows
authentication

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why to use Html.Partial in ASP.Net MVC?

600


Explain what is asp.net mvc?

651


Can we have enum in entity framework?

586


What is viewbag?

612


what is eager loading?

569






Is dapper faster than entity framework?

528


I have 2+ years of fake experience,actually i could not answer for project questions..?how can i answer please suggest me..?

2644


What is domain class model?

514


Is .net core replacing .net framework?

465


How do you assign a value to a complex number 7 how has exception hand changed in .net framework 4.0?

502


Do I need microsoft .net framework?

548


what is more complex to implement property, methods or event? how can I define criteria to compare the difficulty of implementation between them? for example the number of methods wanted to implements property is 2 methods. how many methods I need it to implements events?

1685


how do you query in entity model when the result has a join from from different database other than the entity model?

554


What are the versions of .net framework?

533


What “beforFilter()”,“beforeRender” and “afterFilter” functions do in Controller?

543