Googling examples I’ve seen two ways of specifying the credentials when calling an ASMX webservice.
a) One way is to create a CredentialsCache and assign the NetworkCredential to it.
b) Another way is to set the credentials directly on the client/proxy class.
Why do they just the CredentialsCache? Is it just to specify the authentication method (like BASIC, DIGEST etc) or are there any other reasons to not use the NetworkCredential directly?
You have to create the credentials using the constructor if you want it to work with windows authentication (blogged about it: http://blog.gauffin.org/2012/12/solved-getting-401-unauthorized-while-calling-an-asmx-service-using-windows-authentication/):
All samples using
CredentialsCachedo it without purpose unless they want to specify which authentication option to use (and the server has to support multiple options).NetworkCredentialwill work fine otherwise.