SecurityBindingElement.LocalClientSettings Propiedad
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Obtiene las propiedades de enlace específicas de la configuración de seguridad local utilizada por el cliente.
public:
property System::ServiceModel::Channels::LocalClientSecuritySettings ^ LocalClientSettings { System::ServiceModel::Channels::LocalClientSecuritySettings ^ get(); };
public System.ServiceModel.Channels.LocalClientSecuritySettings LocalClientSettings { get; }
member this.LocalClientSettings : System.ServiceModel.Channels.LocalClientSecuritySettings
Public ReadOnly Property LocalClientSettings As LocalClientSecuritySettings
LocalClientSecuritySettings que representa las propiedades de enlace específicas de la configuración de seguridad local usada por el cliente.
El código siguiente muestra cómo tener acceso a esta propiedad para establecer una propiedad en otro objeto.
// 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);
}
' 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 Shared Function CreateCustomBinding(ByVal clockSkew As TimeSpan) As Binding
Dim standardBinding As WSHttpBinding = New WSHttpBinding(SecurityMode.Message, True)
Dim myCustomBinding As CustomBinding = New CustomBinding(standardBinding)
Dim security As SymmetricSecurityBindingElement = _
myCustomBinding.Elements.Find(Of SymmetricSecurityBindingElement)()
security.LocalClientSettings.MaxClockSkew = clockSkew
security.LocalServiceSettings.MaxClockSkew = clockSkew
' Get the System.ServiceModel.Security.Tokens.SecureConversationSecurityTokenParameters
Dim secureTokenParams As SecureConversationSecurityTokenParameters = _
CType(security.ProtectionTokenParameters, SecureConversationSecurityTokenParameters)
' From the collection, get the bootstrap element.
Dim bootstrap As SecurityBindingElement = secureTokenParams.BootstrapSecurityBindingElement
' Set the MaxClockSkew on the bootstrap element.
bootstrap.LocalClientSettings.MaxClockSkew = clockSkew
bootstrap.LocalServiceSettings.MaxClockSkew = clockSkew
Return myCustomBinding
End Function
Private Sub Run()
' Create a custom binding using the method defined above. The MaxClockSkew is set to 30 minutes.
Dim customBinding As Binding = CreateCustomBinding(TimeSpan.FromMinutes(30))
' Create a ServiceHost instance, and add a metadata endpoint.
' NOTE When using Visual Studio, you must run as administrator.
Dim baseUri As New Uri("http://localhost:1008/")
Dim sh As New ServiceHost(GetType(Calculator), baseUri)
' Optional. Add a metadata endpoint. The method is defined below.
AddMetadataEndpoint(sh)
' Add an endpoint using the binding, and open the service.
sh.AddServiceEndpoint(GetType(ICalculator), customBinding, "myCalculator")
sh.Open()
Console.WriteLine("Listening...")
Console.ReadLine()
End Sub
Private Sub AddMetadataEndpoint(ByRef sh As ServiceHost)
Dim mex As New Uri("http://localhost:1011/metadata/")
Dim sm As New ServiceMetadataBehavior()
sm.HttpGetEnabled = True
sm.HttpGetUrl = mex
sh.Description.Behaviors.Add(sm)
End Sub
La configuración es local en el sentido de que no son la configuración derivada de la directiva de seguridad del servicio. Puede obtener el objeto LocalClientSecuritySettings y utilizarlo para establecer las propiedades de seguridad para este enlace.
Producto | Versiones |
---|---|
.NET | Core 1.0, Core 1.1 |
.NET Framework | 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
UWP | 10.0 |
Comentarios de .NET
.NET es un proyecto de código abierto. Seleccione un vínculo para proporcionar comentarios: