How to call a web service using NT Authentication

J

John Lee

Hi,

I have a web service setup as "Integrated Windows Authentication" only, How
can I set the credential to call the web service from Windows application? I
tried to create the proxy, and the Network Credential class required Domain,
userName and password - that's not a good one because the password should
not be hard-coded. - Even I hardcoded it still give me "401 - not authorized
error" Do I need to use WSE2.0 to call a WS using NT authentication?

Any help and tips will be greatly appreciated!

Thanks a lot!
John
 
J

John Lee

FYI,

ws.Credentials = System.Net.CredentialCache.DefaultCredentials;

will do that job!!!
 
S

Steven Cheng[MSFT]

Hi John,

If Anonymous access was turned off for the Web Service application,
requests are
required to provide credentials. By default calls to the proxy do not
inherit the
credentials of the caller. So if no credentials are explicitly being
supplied the request fails with 401, Access Denied.

#1. To set the credentials on the proxy before you make the call use

PROXY.Credentials = System.Net.CredentialCache.DefaultCredentials

DefaultCredentials represents the system credentials for the current
security context in which the application is running. For a client-side
application, these are usually the Windows credentials (user name,
password, and domain) of the user running the application. For ASP.NET
applications, the default credentials are the user credentials of the
identity for the asp worker process, or the user being impersonated.

#2. If you want to programly generate and set the Credential, you need to
use the System.Net.NetworkCredential class and the
System.Net.CredentialCache class. For example, here is a code snippet that
manually generate a Credential that use NTLM authentication type:

====================================
private void btnCall_Click(object sender, System.EventArgs e)
{
//create webservice proxy
MyService.MyService ms = new AuthClient.MyService.MyService();

//create networkCredential
System.Net.NetworkCredential nc = new System.Net.NetworkCredential
("username","password","domainname");
System.Net.CredentialCache cc = new System.Net.CredentialCache();

//add into CredentialCache and speicfy the NTLM authType
cc.Add(new Uri(ms.Url),"NTLM",nc);

ms.Credentials = cc;

ms.Execute("dfdsfds");

}
==============================

Is this the one you're looking for? If there is anything else unclear,
please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top