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

What is the benefit of entity framework?

769


Will the name change be reflected in any of the existing .net framework 2.0 apis, assemblies, or namespaces?

794


What you mean by routing in mvc?

852


In razor syntax, what is the escape sequence character for @ symbol?

785


Explain the difference between viewbag and viewdata in mvc?

772


explain what is ado.net entity framework?

820


What is NonActionAttribute ?

817


will there be any issues adding a table without primary keys to a data model?

868


Explain the methods used to render the views in mvc?

798


Explain tempdata in asp.net mvc?

836


Can I use razor code in javascript in asp.net mvc?

827


What are actions in mvc?

782


What are the versions of .net framework?

777


What is the meaning of unobtrusive javascript? Explain us by any practical example.

778


Why we need a separate mobile project template, while we can render our web application in mobile ?

893