Questo articolo è stato tradotto automaticamente. Per visualizzare l'articolo in inglese, selezionare la casella di controllo Inglese. È possibile anche visualizzare il testo inglese in una finestra popup posizionando il puntatore del mouse sopra il testo.
Traduzione
Inglese

Metodo EndpointIdentity.CreateRsaIdentity (X509Certificate2)

 

Data di pubblicazione: ottobre 2016

Crea un'identità RSA con il certificato X.509 specificato.

Spazio dei nomi:   System.ServiceModel
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

public static EndpointIdentity CreateRsaIdentity(
	X509Certificate2 certificate
)

Parametri

certificate
Type: System.Security.Cryptography.X509Certificates.X509Certificate2

Classe X509Certificate2 contenente il certificato per l'identità RSA.

Valore restituito

Type: System.ServiceModel.EndpointIdentity

Classe EndpointIdentity RSA associata al parametro certificate specificato.

Exception Condition
ArgumentNullException

certificate è null.

NotSupportedException

Il parametro certificate non è un certificato RSA.

A secure indigo2 client that connects to an endpoint with this identity verifies that the claims presented by the server contain a claim that contains the RSA public key obtained from the certificate used to construct this identity.

This static method creates an instance of T:System.ServiceModel.RsaEndpointIdentity by calling its constructor, M:System.ServiceModel.RsaEndpointIdentity.#ctor(System.Security.Cryptography.X509Certificates.X509Certificate2).

The following code shows how to call this method.

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;

.NET Framework
Disponibile da 3.0
Torna all'inizio
Mostra: