本文整理汇总了C#中System.ServiceModel.EndpointIdentity.CreateDnsIdentity方法的典型用法代码示例。如果您正苦于以下问题:C# EndpointIdentity.CreateDnsIdentity方法的具体用法?C# EndpointIdentity.CreateDnsIdentity怎么用?C# EndpointIdentity.CreateDnsIdentity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了EndpointIdentity.CreateDnsIdentity方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateRSAIdentity
public static void CreateRSAIdentity()
{
// Create a ServiceHost for the CalculatorService type. Base Address is supplied in app.config.
using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService)))
{
// The base address is read from the app.config.
Uri dnsrelativeAddress = new Uri(serviceHost.BaseAddresses[0], "dnsidentity");
Uri certificaterelativeAddress = new Uri(serviceHost.BaseAddresses[0], "certificateidentity");
Uri rsarelativeAddress = new Uri(serviceHost.BaseAddresses[0], "rsaidentity");
// Set the service's X509Certificate to protect the messages.
serviceHost.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine,
StoreName.My,
X509FindType.FindBySubjectDistinguishedName,
"CN=identity.com, O=Contoso");
//Cache a reference to the server's certificate.
X509Certificate2 servercert = serviceHost.Credentials.ServiceCertificate.Certificate;
//Create endpoints for the service using a WSHttpBinding set for anonymous clients.
WSHttpBinding wsAnonbinding = new WSHttpBinding(SecurityMode.Message);
//Clients are anonymous to the service.
wsAnonbinding.Security.Message.ClientCredentialType = MessageCredentialType.None;
//Secure conversation (session) is turned off.
wsAnonbinding.Security.Message.EstablishSecurityContext = false;
//Create a service endpoint and change its identity to the DNS for an X509 Certificate.
ServiceEndpoint ep = serviceHost.AddServiceEndpoint(typeof(ICalculator),
wsAnonbinding,
String.Empty);
EndpointAddress epa = new EndpointAddress(dnsrelativeAddress, EndpointIdentity.CreateDnsIdentity("identity.com"));
ep.Address = epa;
//Create a service endpoint and change its identity to the X509 certificate's RSA key value.
ServiceEndpoint ep3 = serviceHost.AddServiceEndpoint(typeof(ICalculator), wsAnonbinding, String.Empty);
EndpointAddress epa3 = new EndpointAddress(rsarelativeAddress, EndpointIdentity.CreateRsaIdentity(servercert));
ep3.Address = epa3;