Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

SecurityBindingElement.LocalClientSettings Property

Gets the binding properties specific to local security settings used by the client.

Namespace:  System.ServiceModel.Channels
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

public LocalClientSecuritySettings LocalClientSettings { get; }

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);
        }



.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

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.

Community Additions

ADD
Show:
© 2015 Microsoft