Udostępnij za pośrednictwem


Instrukcje: Określanie typu poświadczeń klienta

Po ustawieniu trybu zabezpieczeń (transportu lub komunikatu) możesz ustawić typ poświadczeń klienta. Ta właściwość określa typ poświadczeń, które klient musi dostarczyć do usługi na potrzeby uwierzytelniania. Aby uzyskać więcej informacji na temat ustawiania trybu zabezpieczeń (niezbędny krok przed ustawieniem typu poświadczeń klienta), zobacz Instrukcje: ustawianie trybu zabezpieczeń.

Aby ustawić typ poświadczeń klienta w kodzie

  1. Utwórz wystąpienie powiązania, którego będzie używać usługa. W tym przykładzie użyto WSHttpBinding powiązania.

  2. Mode Ustaw właściwość na odpowiednią wartość. W tym przykładzie jest używany tryb komunikatu.

  3. ClientCredentialType Ustaw właściwość na odpowiednią wartość. W tym przykładzie ustawiono użycie uwierzytelniania systemu Windows (Windows).

    ServiceHost myServiceHost = new ServiceHost(typeof(CalculatorService));
    // Create a binding to use.
    WSHttpBinding binding = new WSHttpBinding();
    binding.Security.Mode = SecurityMode.Message;
    binding.Security.Message.ClientCredentialType =
        MessageCredentialType.Windows;
    
    Dim myServiceHost As New ServiceHost(GetType(CalculatorService))
    ' Create a binding to use.
    Dim binding As New WSHttpBinding()
    binding.Security.Mode = SecurityMode.Message
    binding.Security.Message.ClientCredentialType = _
    MessageCredentialType.Windows
    

Aby ustawić typ poświadczeń klienta w konfiguracji

  1. Dodaj element <system.serviceModel> do pliku konfiguracji.

  2. Jako element podrzędny dodaj <element bindings> .

  3. Dodaj odpowiednie powiązanie. W tym przykładzie użyto <elementu wsHttpBinding> .

  4. <Dodaj element powiązania> i ustaw name atrybut na odpowiednią wartość. W tym przykładzie użyto nazwy "SecureBinding".

  5. <security> Dodaj powiązanie. mode Ustaw atrybut na odpowiednią wartość. W tym przykładzie ustawiono go na "Message"wartość .

  6. Dodaj element <message> lub <transport> zgodnie z trybem zabezpieczeń. clientCredentialType Ustaw atrybut na odpowiednią wartość. W tym przykładzie użyto wartości "Windows".

    <system.serviceModel>  
      <bindings>  
        <wsHttpBinding>  
          <binding name="SecureBinding">  
            <security mode="Message">  
                 <message clientCredentialType="Windows" />  
             </security>  
          </binding>  
        </wsHttpBinding>  
      </bindings>  
    </system.serviceModel>  
    

Zobacz też