WCF 使用证书加密
2011-08-21 12:49
218 查看
生成两个证书:
makecert 命令参考:证书创建工具 (Makecert.exe)
certmgr命令参考: 证书管理器工具 (Certmgr.exe)
makecert -sr CurrentUser -ss My -a sha1 -n CN=localhost -sky exchange -pe
certmgr.exe -add -r CurrentUser -s My -c -n localhost -r CurrentUser -s TrustedPeople
makecert.exe -sr CurrentUser -ss My -a sha1 -n CN=WCFUser -sky exchange -pe
certmgr.exe -add -r CurrentUser -s My -c -n WCFUser -r CurrentUser -s TrustedPeople
通过证书管理工具可以看到刚才生成的证书
在服务端添加证书:
客户端:
makecert 命令参考:证书创建工具 (Makecert.exe)
certmgr命令参考: 证书管理器工具 (Certmgr.exe)
makecert -sr CurrentUser -ss My -a sha1 -n CN=localhost -sky exchange -pe
certmgr.exe -add -r CurrentUser -s My -c -n localhost -r CurrentUser -s TrustedPeople
makecert.exe -sr CurrentUser -ss My -a sha1 -n CN=WCFUser -sky exchange -pe
certmgr.exe -add -r CurrentUser -s My -c -n WCFUser -r CurrentUser -s TrustedPeople
通过证书管理工具可以看到刚才生成的证书
在服务端添加证书:
using System; using System.ServiceModel; using System.ServiceModel.Description; namespace ExchangeService { public class Program { public static void Main(string[] args) { Uri address = new Uri("http://localhost:8001/TradeService"); WSHttpBinding binding = new WSHttpBinding(); Type contract = typeof(ExchangeService.ITradeService); ServiceHost host = new ServiceHost(typeof(TradeService)); host.AddServiceEndpoint(contract, binding, address); // Add Auditing to the service ServiceSecurityAuditBehavior auditProvider = host.Description.Behaviors.Find<ServiceSecurityAuditBehavior>(); if (auditProvider == null) { auditProvider = new ServiceSecurityAuditBehavior(); } auditProvider.AuditLogLocation = AuditLogLocation.Application; auditProvider.MessageAuthenticationAuditLevel = AuditLevel.SuccessOrFailure; auditProvider.ServiceAuthorizationAuditLevel = AuditLevel.SuccessOrFailure; host.Description.Behaviors.Add(auditProvider); host.Open(); Console.WriteLine("The WCF Management trading service is available."); Console.ReadKey(); } } }
客户端:
using System; using System.ServiceModel.Channels; using System.ServiceModel; using System.Threading; namespace ExchangeService { class Program { static void Main( string[] args ) { EndpointAddress address = new EndpointAddress("http://localhost:8001/TradeService"); WSHttpBinding binding = new WSHttpBinding(); System.ServiceModel.ChannelFactory<ITradeService> cf = new ChannelFactory<ITradeService>(binding, address); ITradeService proxy = cf.CreateChannel(); Console.WriteLine("\nTrade IBM"); try { double result = proxy.TradeSecurity("IBM", 1000); Console.WriteLine("Cost was " + result); Console.WriteLine("\nTrade MSFT"); result = proxy.TradeSecurity("MSFT", 2000); Console.WriteLine("Cost was " + result); } catch (Exception ex) { Console.Write("Can not perform task. Error Message - " + ex.Message); } Console.WriteLine("\n\nPress <enter> to exit..."); Console.ReadLine(); } } }
相关文章推荐
- 【WCF】使用数字证书加密通讯
- WCF开发框架之证书加密使用说明书(转载)
- WCF使用X509证书数据加密
- WCF使用安全证书验证消息加密
- 【WCF】使用数字证书加密通讯
- WCF开发框架之证书加密使用说明书
- WCF使用证书与加密
- wcf使用X509证书加密传输
- 使用数字证书技术来保证WCF传输中的数据加密
- WCF开发框架之证书加密使用说明书
- WCF开发框架之证书加密使用说明书
- WCF使用安全证书验证消息加密
- 外业记录:在Windows Azure应用程序中使用基于证书的加密
- 使用X.509数字证书加密解密实务(三)-- 使用RSA证书结合对称加密技术加密长数据
- WCF使用X509证书
- WCF消息安全模式之自定义用户名密码:Message CustomUserNamePassword wsHttpBinding 使用Windows Services宿主以及客户端免证书验证
- 外业记录:在Windows Azure应用程序中使用基于证书的加密
- C#使用RSA证书文件加密和解密示例
- 使用X.509数字证书加密解密实务(一)-- 证书的获得和管理
- 使用X.509数字证书加密解密实务(一)-- 证书的获得和管理