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
Create an instance of the binding that the service will use. This example uses the WSHttpBinding binding.
Set the Mode property to an appropriate value. This example uses the Message mode.
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
Add a <system.ServiceModel> element to the configuration file.
As a child element, add a <bindings> element.
Add an appropriate binding. This example uses the <wsHttpBinding> element.
Add a <binding> element and set the
name
attribute to an appropriate value. This example uses the name "SecureBinding".Add a
<security>
binding. Set themode
attribute to an appropriate value. This example sets it to"Message"
.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
Concepts
© 2007 Microsoft Corporation. All rights reserved.
Last Published: 2010-03-21