需引用 System.Net;
windows集成验证:
localhost.WebService math = new localhost.WebService();
// Create a new instance of CredentialCache.
CredentialCache credentialCache = new CredentialCache();
// Create a new instance of NetworkCredential using the client
// credentials.
NetworkCredential credentials = new NetworkCredential("windows登录用户名", "登录密码");
// Add the NetworkCredential to the CredentialCache.
credentialCache.Add(new Uri(math.Url), "NTLM", credentials);
// Add the CredentialCache to the proxy class credentials.
math.Credentials = credentialCache;
// Call the method on the proxy class.
string Str = math.HelloWorld("keycom");
基本身份验证:
localhost.WebService math = new localhost.WebService();
math.Credentials = new System.Net.NetworkCredential("windows登录用户名", "登录密码");
string Str = math.HelloWorld("keycom");
windows集成验证:
localhost.WebService math = new localhost.WebService();
// Create a new instance of CredentialCache.
CredentialCache credentialCache = new CredentialCache();
// Create a new instance of NetworkCredential using the client
// credentials.
NetworkCredential credentials = new NetworkCredential("windows登录用户名", "登录密码");
// Add the NetworkCredential to the CredentialCache.
credentialCache.Add(new Uri(math.Url), "NTLM", credentials);
// Add the CredentialCache to the proxy class credentials.
math.Credentials = credentialCache;
// Call the method on the proxy class.
string Str = math.HelloWorld("keycom");
基本身份验证:
localhost.WebService math = new localhost.WebService();
math.Credentials = new System.Net.NetworkCredential("windows登录用户名", "登录密码");
string Str = math.HelloWorld("keycom");