다음을 통해 공유


WebClientProtocol.Credentials 속성

정의

XML 웹 서비스 클라이언트 인증에 대한 보안 자격 증명을 가져오거나 설정합니다.

public:
 property System::Net::ICredentials ^ Credentials { System::Net::ICredentials ^ get(); void set(System::Net::ICredentials ^ value); };
public System.Net.ICredentials Credentials { get; set; }
member this.Credentials : System.Net.ICredentials with get, set
Public Property Credentials As ICredentials

속성 값

XML 웹 서비스 클라이언트의 경우입니다 ICredentials .

예제

다음 예제는 명명 Math된 XML 웹 서비스를 호출하는 ASP.NET Web Form입니다. 함수 내에서 EnterBtn_Click 웹 양식은 속성을 사용하여 인증 자격 증명을 Credentials 명시적으로 설정합니다. 사용자 이름, 암호 및 도메인은 클래스의 생성자에 NetworkCredential 전달됩니다.

중요합니다

이 예제에는 잠재적인 보안 위협인 사용자 입력을 허용하는 텍스트 상자가 있습니다. 기본적으로 ASP.NET 웹 페이지는 사용자 입력에 스크립트 또는 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="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>

설명

이 속성을 사용하는 Credentials 경우 XML 웹 서비스 클라이언트는 구현하는 ICredentialsNetworkCredential클래스를 인스턴스화한 다음 인증 메커니즘과 관련된 클라이언트 자격 증명을 설정해야 합니다. 클래스는 NetworkCredential 기본, 다이제스트, NTLM 및 Kerberos 인증 메커니즘을 사용하여 인증 자격 증명을 설정하는 데 사용할 수 있습니다.

속성이 Credentials 설정된 CredentialCache.DefaultCredentials 경우 클라이언트는 서버 구성 방법에 따라 Kerberos 및/또는 NTLM 인증을 수행하도록 서버와 협상합니다.

적용 대상

추가 정보