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

What is entityset? : Entity framework

0 Answers  


if u add an import stmt to an application u can do the same by adding reference to the apllication then what is the diff bet these two ?

1 Answers  


What are the sub types of ActionResult?

0 Answers  


I want ask from plz smaple example code for Biztalkk server

0 Answers  


Requirement is: try { \\SQL Query } catch(Exception i) { print a } catch(SQLQueryException e) { \\SQL Query } Qu)I Got Exception in "try" block. Which "catch" statement (i.e. 1st catch or 2nd catch ) catches the exception and Why???

6 Answers   3i Infotech,






About Assembly in .NET, types of assemblies, their difference, How to register into GAC. How to generate the strong names & its use ?

6 Answers   Infosys, Microsoft, MMTS,


What is MSIL, IL, CTS?

13 Answers  


what is MetadData?. What is CTS? Type of Join in SQL Server? What is diffrence between Primary Key and Unique Key?

7 Answers   FutureSoft,


Does windows 10 need .net framework?

0 Answers  


How to enable Attribute Routing?

0 Answers  


How could we achieve Langauge Interoperability through "CLS"?? Please Expalin in detail with Example.. Thanks for the Help!!!!!

2 Answers   HCL,


Can a view be shared across multiple controllers? If yes, how we can do that?

0 Answers  


Categories