WebClientProtocol.Credentials プロパティ
アセンブリ: System.Web.Services (system.web.services.dll 内)

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)
XML Web サービス クライアントの ICredentials。

Credentials プロパティを使用している場合、XML Web サービス クライアントは、NetworkCredential などの ICredentials を実装しているクラスをインスタンス化してから、認証機構に固有のクライアント資格情報を設定する必要があります。NetworkCredential クラスを使用すると、基本、ダイジェスト、NTLM、Kerberos の各認証機構を使用して、認証資格情報を設定できます。
Credentials プロパティが CredentialCache.DefaultCredentials に設定されている場合、クライアントはサーバーとネゴシエートするとき、サーバーの構成に応じて、Kerberos 認証と NTLM 認証、またはそのいずれかを使用します。

XML Web サービス (Math) を呼び出す ASP.NET Web フォームの例を次に示します。この Web フォームでは、EnterBtn_Click 関数の中で、Credentials プロパティを使用して認証資格情報を明示的に設定します。ユーザー名、パスワード、およびドメインは NetworkCredential クラスのコンストラクタに渡されます。
<%@ 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>

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
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- WebClientProtocol.Credentials プロパティのページへのリンク