EndpointIdentity.CreateDnsIdentity(String) Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Crée une identité DNS avec un nom DNS spécifié.
public:
static System::ServiceModel::EndpointIdentity ^ CreateDnsIdentity(System::String ^ dnsName);
public static System.ServiceModel.EndpointIdentity CreateDnsIdentity (string dnsName);
static member CreateDnsIdentity : string -> System.ServiceModel.EndpointIdentity
Public Shared Function CreateDnsIdentity (dnsName As String) As EndpointIdentity
Paramètres
- dnsName
- String
Nom de l'identité DNS.
Retours
EndpointIdentity DNS associée au dnsName
spécifié.
Exceptions
dnsName
a la valeur null
.
Exemples
L'exemple de code suivant montre comment appeler cette méthode.
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;
Remarques
Un client WCF sécurisé qui se connecte à un point de terminaison avec cette identité vérifie que les revendications présentées par le serveur contiennent une revendication DNS qui représente cette identité.
Cette méthode statique crée une instance de DnsEndpointIdentity en appelant son constructeur DnsEndpointIdentity.