Gets or sets security credentials for XML Web service client authentication.
Namespace: System.Web.Services.Protocols
Assembly: System.Web.Services (in system.web.services.dll)

Syntax
Visual Basic (Declaration)
Public Property Credentials As ICredentials
Dim instance As WebClientProtocol
Dim value As ICredentials
value = instance.Credentials
instance.Credentials = value
public ICredentials Credentials { get; set; }
public:
property ICredentials^ Credentials {
ICredentials^ get ();
void set (ICredentials^ value);
}
/** @property */
public ICredentials get_Credentials ()
/** @property */
public void set_Credentials (ICredentials value)
public function get Credentials () : ICredentials
public function set Credentials (value : ICredentials)
Property Value
The
ICredentials for the XML Web service client.

Remarks
When using the Credentials property, a XML Web service client must instantiate a class implementing ICredentials, such as NetworkCredential, and then set the client credentials specific to the authentication mechanism. The NetworkCredential class can be used to set authentication credentials using the basic, digest, NTLM and Kerberos authentication mechanisms.
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.

Example
The following example is an ASP.NET Web Form, which calls an XML Web service named Math. Within the EnterBtn_Click function, the Web Form explicitly sets authentication credentials using the Credentials property. The user name, password and domain are passed into the constructor for the NetworkCredential class.
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Net" %>
<html>
<script language="VB" runat="server">
Sub EnterBtn_Click(src As Object, e As EventArgs)
Dim math As New MyMath.Math()
' Obtain password from a secure store.
Dim SecurelyStoredPassword As String = String.Empty
' Set the client-side credentials using the Credentials property.
Dim credentials = New NetworkCredential("Joe", SecurelyStoredPassword, "mydomain")
math.Credentials = credentials
Dim iTotal As Integer = math.Add(Convert.ToInt32(Num1.Text), Convert.ToInt32(Num2.Text))
Total.Text = "Total: " + iTotal.ToString()
End Sub
</script>
<body>
<form action="MathClient.aspx" runat=server>
Enter the two numbers you want to add and then press the Total button.
<p>
Number 1: <asp:textbox id="Num1" runat=server/> +
Number 2: <asp:textbox id="Num2" runat=server/> =
<asp:button text="Total" Onclick="EnterBtn_Click" runat=server/>
<p>
<asp:label id="Total" runat=server/>
</form>
</body>
</html>
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Net" %>
<html>
<script language="C#" runat="server">
void EnterBtn_Click(Object Src, EventArgs E)
{
MyMath.Math math = new MyMath.Math();
// Obtain password from a secure store.
String SecurelyStoredPassword = String.Empty;
// Set the client-side credentials using the Credentials property.
ICredentials credentials = new NetworkCredential("Joe",SecurelyStoredPassword,"mydomain");
math.Credentials = credentials;
int total = math.Add(Convert.ToInt32(Num1.Text), Convert.ToInt32(Num2.Text));
Total.Text = "Total: " + total.ToString();
}
</script>
<body>
<form action="MathClient.aspx" runat=server>
Enter the two numbers you want to add and then press the Total button.
<p>
Number 1: <asp:textbox id="Num1" runat=server/> +
Number 2: <asp:textbox id="Num2" runat=server/> =
<asp:button text="Total" Onclick="EnterBtn_Click" runat=server/>
<p>
<asp:label id="Total" runat=server/>
</form>
</body>
</html>
<%@ Page Language="JSCRIPT" src="source.js" %>
<%@ Import Namespace="System.Net" %>
<html>
<script language="JSCRIPT" runat="server">
function EnterBtn_Click(src : Object, e : EventArgs){
var math : MyMath.Math = new MyMath.Math()
// Obtain password from a secure store.
var SecurelyStoredPassword
// Set the client-side credentials using the Credentials property.
var credentials : NetworkCredential = new NetworkCredential("Joe", SecurelyStoredPassword, "mydomain")
math.Credentials = credentials
var iTotal : int = math.Add(Convert.ToInt32(Num1.Text), Convert.ToInt32(Num2.Text))
Total.Text = "Total: " + iTotal.ToString()
}
</script>
<body>
<form action="MathClient.aspx" runat=server>
Enter the two numbers you want to add and then press the Total button.
<p>
Number 1: <asp:textbox id="Num1" runat=server/> +
Number 2: <asp:textbox id="Num2" runat=server/> =
<asp:button text="Total" Onclick="EnterBtn_Click" runat=server/>
<p>
<asp:label id="Total" runat=server/>
</form>
</body>
</html>

Platforms
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

Version Information
.NET Framework
Supported in: 2.0, 1.1, 1.0
.NET Compact Framework
Supported in: 2.0, 1.0

See Also