다음을 통해 공유


How to: Specify the Client Credential Type

After setting a security mode (either transport or message), you have the option of setting the client credential type. This property specifies what type of credential the client must provide to the service for authentication. For more information about setting the security mode (a necessary step before setting the client credential type), see How to: Set the Security Mode.

To set the client credential type in code

  1. Create an instance of the binding that the service will use. This example uses the WSHttpBinding binding.

  2. Set the Mode property to an appropriate value. This example uses the Message mode.

  3. Set the ClientCredentialType property to an appropriate value. This example sets it to use Windows authentication (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
    
    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;
    

To set the client credential type in configuration

  1. Add a <system.ServiceModel> element to the configuration file.

  2. As a child element, add a <bindings> element.

  3. Add an appropriate binding. This example uses the <wsHttpBinding> element.

  4. Add a <binding> element and set the name attribute to an appropriate value. This example uses the name "SecureBinding".

  5. Add a <security> binding. Set the mode attribute to an appropriate value. This example sets it to "Message".

  6. Add either a <message> or <transport> element, as determined by the security mode. Set the clientCredentialType attribute to an appropriate value. This example uses "Windows".

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

See Also

Tasks

How to: Set the Security Mode

Concepts

Securing Services


© 2007 Microsoft Corporation. All rights reserved.
Build Date: 2009-08-07