Wednesday, December 31, 2008

Log in to web service programatically

Web service calls that are exposed to the public but which you don't want open to public calls can be secured using directory security on the directory IIS uses. This is only a valid method if the call is made over a controlled network since basic authentication password can be snooped.

Microsoft has a great page on how to use it, so I will only summarize

NavCustomer.CustomerService navCustService = new NavCustomer.CustomerService();
CredentialCache credentialCache = new CredentialCache();
NetworkCredential credentials = new NetworkCredential(
credentialCache.Add(new Uri(navCustService.Url), "Basic", credentials);
navCustService.Credentials = credentialCache;

No comments: