How to ensure the credentials for WebService using Windows
authentication



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

Post New Answer

More Dot Net Framework Interview Questions

Explain what is routing?

0 Answers  


Briefly describe the roles of clr in .net framework?

0 Answers  


Difference between manifest , metadata?

3 Answers   Soma Technology, TCS,


Microsoft introduced c# as a de facto language of the .NET platform. What is mean by de facto and fot what purpose? Please answer me. Advance thanks.

3 Answers   Excel,


What are Satellite Assemblies? How you will create this?

4 Answers  






What are Resource Files ? How are they used in .NET

1 Answers  


What is needed for running an application built on winfx on the .net framework 3.0?

0 Answers  


How does servicing work for the .net framework 3.0?

0 Answers  


Please explain me what the project manager will ask in the interview.The interview is for senior position in .Net (5 years experience )

0 Answers   NNN,


How to create an alias name for a namespace?

4 Answers   IBM,


What is conceptual model? : Entity framework

0 Answers  


What is an asynchronous controller in asp.net mvc?

0 Answers  


Categories