Gets or sets security credentials for XML Web service client authentication.
[Visual Basic] Public Property Credentials As ICredentials [C#] public ICredentials Credentials {get; set;} [C++] public: __property ICredentials* get_Credentials(); public: __property void set_Credentials(ICredentials*); [JScript] public function get Credentials() : ICredentials; public function set Credentials(ICredentials);
The ICredentials for the XML Web service client.
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.
[Visual Basic, C#, JScript] 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.
[Visual Basic] <%@ 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> [C#] <%@ 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> [JScript] <%@ 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>
[C++] No example is available for C++. To view a Visual Basic, C#, or JScript example, click the Language Filter button
in the upper-left corner of the page.
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework - Windows CE .NET
WebClientProtocol Class | WebClientProtocol Members | System.Web.Services.Protocols Namespace | ICredentials | NetworkCredential