When the Credentials property is set to CredentialCache.DefaultCredentials then the client negotiates with the server to do Kerberos and/or NTLM authentication depending on how the server is configured.
The following code example sets the client credentials passed to a Web service method using Windows authentication.
Imports System
Imports System.Web.Services.Protocols
Imports System.Net
Imports MyMath
Public Class Calculator
Public Shared Sub Main()
' Create a new instance of the proxy class to an
' Web service method.
Dim mathproxy As MyMath.Math = New MyMath.Math()
' Create a new instance of CredentialCache.
<br /><b> Dim mycredentialCache As CredentialCache = New CredentialCache()</b>
' Create a new instance of NetworkCredential using the client
' credentials.
<br /><b> Dim credentials As NetworkCredential = New _</b><br /><b> NetworkCredential(UserName,SecurelyStoredPasword,Domain)</b>
' Add the NetworkCredential to the CredentialCache.
<br /><b> mycredentialCache.Add(New Uri(mathproxy.Url), "Basic", _</b><br /><b> credentials)</b>
' Add the CredentialCache to the proxy class credentials.
<br /><b> mathproxy.Credentials = mycredentialCache</b>
' Call the method on the proxy class.
Dim result As Integer
result = mathproxy.Add(3,5)
End Sub
End Class
using System;
using System.Web.Services.Protocols;
using System.Net;
using MyMath;
public class Calculator
{
public static void Main()
{
// Create a new instance of the proxy class to an XML
// Web service method.
MyMath.Math math = new MyMath.Math();
// Create a new instance of CredentialCache.
<br /><b> CredentialCache credentialCache = new CredentialCache();</b>
// Create a new instance of NetworkCredential using the client
// credentials.
NetworkCredential credentials = new
<br /><b> NetworkCredential(UserName,SecurelyStroredPassword,Domain);</b>
// Add the NetworkCredential to the CredentialCache.
<br /><b> credentialCache.Add(new Uri(math.Url), </b><br /><b> "Basic", credentials);</b>
// Add the CredentialCache to the proxy class credentials.
<br /><b> math.Credentials = credentialCache;</b>
// Call the method on the proxy class.
int result = math.Add(3,5);
}
}