博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
wcf 配置与代码创建
阅读量:6204 次
发布时间:2019-06-21

本文共 2967 字,大约阅读时间需要 9 分钟。

private static Binding CreateMultiFactorAuthenticationBinding(){    var httpsTransport = new HttpsTransportBindingElement();    // The message security binding element will be configured to require 2 tokens:    // 1) A username-password encrypted with the service token    // 2) A client certificate used to sign the message    // Create symmetric security binding element with encrypted username-password token.    // Symmetric key is encrypted with server certificate.    var messageSecurity = SecurityBindingElement.CreateUserNameForCertificateBindingElement();    messageSecurity.AllowInsecureTransport = false;    // Require client certificate as endorsing supporting token for all requests from client to server    var clientX509SupportingTokenParameters = new X509SecurityTokenParameters                                                    {                                                        InclusionMode =                                                            SecurityTokenInclusionMode.AlwaysToRecipient                                                    };    messageSecurity.EndpointSupportingTokenParameters.Endorsing.Add(clientX509SupportingTokenParameters);    return new CustomBinding(messageSecurity, httpsTransport);}

 

Registering WCF-servicesvar returnFaults = new ServiceDebugBehavior {IncludeExceptionDetailInFaults = true};var metaData = new ServiceMetadataBehavior {HttpsGetEnabled = true};var serviceCredentials = new ServiceCredentials();// Configure service sertificateserviceCredentials.ServiceCertificate.SetCertificate(    StoreLocation.LocalMachine,     StoreName.My,     X509FindType.FindBySubjectName,    "ServerCertificate");// Configure client certificate authentication modeserviceCredentials.ClientCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.ChainTrust;// Add custom username-password validatorserviceCredentials.UserNameAuthentication.UserNamePasswordValidationMode =    UserNamePasswordValidationMode.Custom;serviceCredentials.UserNameAuthentication.CustomUserNamePasswordValidator =    _container.Resolve
();// Add custom certificate validatorserviceCredentials.ClientCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.Custom;serviceCredentials.ClientCertificate.Authentication.CustomCertificateValidator = _container.Resolve
();var serviceModel = new DefaultServiceModel();serviceModel.AddEndpoints( WcfEndpoint.ForContract
().BoundTo(CreateMultiFactorAuthenticationBinding()));serviceModel.BaseAddresses.Add(new Uri("https://server.com/MyServiceImplementation.svc"));serviceModel.AddExtensions(serviceCredentials);serviceModel.AddExtensions(metaData);_container.AddFacility
(f => f.CloseTimeout = TimeSpan.Zero) .Register(Component.For
() .ImplementedBy
() .AsWcfService(serviceModel), Component.For
().Instance(returnFaults));

 

转载地址:http://xgmca.baihongyu.com/

你可能感兴趣的文章
supervisor守护进程
查看>>
maven详解之坐标与依赖
查看>>
在屏幕上打印杨辉三角
查看>>
其他大神的配置 nginx 配置参考
查看>>
Cisco Nexus 1000V
查看>>
我的友情链接
查看>>
MAC下面maven如何设置让其实下载源码
查看>>
查看NVIDIA使用率工具目录
查看>>
PostgreSQL学习手册(二) 模式(Schema)
查看>>
[iOS Animation]-CALayer 性能优化实例
查看>>
Nagios 安装及常见错误
查看>>
我的友情链接
查看>>
python模块学习(1)
查看>>
Groovy在Spring中的简单使用实例
查看>>
Linux 下的 hosts文件
查看>>
升级nginx,查看已经安装的模块,并隐藏或者修改版本号
查看>>
判断 CGRect是否“为空”
查看>>
MySQL日期时间函数大全(转)
查看>>
Android版添加phonegap--websocket客户端插件教程
查看>>
android控件的隐藏与显示
查看>>