本文整理汇总了C#中System.ServiceModel.Channels.SecurityBindingElement.LocalClientSettings属性的典型用法代码示例。如果您正苦于以下问题:C# SecurityBindingElement.LocalClientSettings属性的具体用法?C# SecurityBindingElement.LocalClientSettings怎么用?C# SecurityBindingElement.LocalClientSettings使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。
在下文中一共展示了SecurityBindingElement.LocalClientSettings属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: CreateCustomBinding
// 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);
}
开发者ID:.NET开发者,项目名称:System.ServiceModel.Channels,代码行数:50,代码来源:SecurityBindingElement.LocalClientSettings
注:本文中的System.ServiceModel.Channels.SecurityBindingElement.LocalClientSettings属性示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论