SecurityBindingElement.LocalClientSettings Property
.NET Framework 4
Gets the binding properties specific to local security settings used by the client.
Assembly: System.ServiceModel (in System.ServiceModel.dll)
Property Value
Type: System.ServiceModel.Channels.LocalClientSecuritySettingsThe LocalClientSecuritySettings.
The settings are local in the sense that they are not settings derived from the security policy of the service. You can get the LocalClientSecuritySettings object and use it to set security properties for this binding.
The following code shows how to access this property to set a property in another object.
// This method returns a custom binding created from a WSHttpBinding. Alter the method
// to use the appropriate binding for your service, with the appropriate settings.
public static Binding CreateCustomBinding(TimeSpan clockSkew)
{
WSHttpBinding standardBinding = new WSHttpBinding(SecurityMode.Message, true);
CustomBinding myCustomBinding = new CustomBinding(standardBinding);
SymmetricSecurityBindingElement security =
myCustomBinding.Elements.Find<SymmetricSecurityBindingElement>();
security.LocalClientSettings.MaxClockSkew = clockSkew;
security.LocalServiceSettings.MaxClockSkew = clockSkew;
// Get the System.ServiceModel.Security.Tokens.SecureConversationSecurityTokenParameters
SecureConversationSecurityTokenParameters secureTokenParams =
(SecureConversationSecurityTokenParameters)security.ProtectionTokenParameters;
// From the collection, get the bootstrap element.
SecurityBindingElement bootstrap = secureTokenParams.BootstrapSecurityBindingElement;
// Set the MaxClockSkew on the bootstrap element.
bootstrap.LocalClientSettings.MaxClockSkew = clockSkew;
bootstrap.LocalServiceSettings.MaxClockSkew = clockSkew;
return myCustomBinding;
}
private void Run()
{
// Create a custom binding using the method defined above. The MaxClockSkew is set to 30 minutes.
Binding customBinding= CreateCustomBinding(TimeSpan.FromMinutes(30));
// Create a ServiceHost instance, and add a metadata endpoint.
// NOTE When using Visual Studio, you must run as administrator.
Uri baseUri = new Uri("http://localhost:1008/");
ServiceHost sh = new ServiceHost(typeof(Calculator), baseUri);
// Optional. Add a metadata endpoint. The method is defined below.
AddMetadataEndpoint(ref sh);
// Add an endpoint using the binding, and open the service.
sh.AddServiceEndpoint(typeof(ICalculator), customBinding, "myCalculator");
sh.Open();
Console.WriteLine("Listening...");
Console.ReadLine();
}
private void AddMetadataEndpoint(ref ServiceHost sh)
{
Uri mex = new Uri(@"http://localhost:1001/metadata/");
ServiceMetadataBehavior sm = new ServiceMetadataBehavior();
sm.HttpGetEnabled = true;
sm.HttpGetUrl = mex;
sh.Description.Behaviors.Add(sm);
}
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.