.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Web Services >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Pass Credentials to a Web Service that Uses Basic Authentication

Posted By:Dhivakaran       Posted Date: October 25, 2010    Points: 15    Category: Web Services    URL: http://www.dotnetspark.com  

When you're working with Web Services that require authentication, you'll need a way to pass credentials. This snippet shows you how to pass a user name and password to a Web Service that is configured for Basic Authentication.
 

use the below namespace

using System.Net;

 

localhost.MyWebService myService = new localhost.MyWebService();

System.Net.CredentialCache myCredentials = new System.Net.CredentialCache();

NetworkCredential netCred = new NetworkCredential("UserName", "Password");

myCredentials.Add(new Uri(myService.Url), "Basic", netCred);

myService.Credentials = myCredentials;

 

// Now call methods on the myService object...

 

 

we should be aware that by using Basic Authentication the user name and password are sent as Base 64 encoded text. That is as secure as sending it as plain text, so the best way to use this authentication mechanism is in combination with SSL. This way, the data is encrypted .

 


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend