Service References Credentials

By Gord at August 27, 2010 15:06
Filed Under: .Net, .Net Framework 4.0, ASP.NET

There isn't a whole lot of information on using Service References over Web References when it comes to passing in username and password credentials. 

 

Normally with a Web Reference you'd do this:

            MyWebRef.MyClient webClient = new MyWebRef.MyClient();
            NetworkCredential credentials = new NetworkCredential("myUser", "myPassword");
            webClient.Credentials = credentials;

 

 

The Alternative code to that:

            MyServiceRef.MyClient client = new MyServiceRef.MyClient();
            client.ClientCredentials.UserName.UserName = "myUser";
            client.ClientCredentials.UserName.Password = "myPassword";

 

While this may not seem much different, it isn't immediately obvious where to look for setting the username and password inside the Service Reference.

 

 

About the author

Gord graduated from Carleton University with a bachelors of Computer Science with minors in both Philosophy and Mathematics.  His post graduate career started in 2005 as a Systems Administrator until becoming a .Net Web Developer 2 years later.  Since then, he has moved on to being a more generic Systems Developer, focusing on intersystem communication, design, and architecture.

Page List