EndpointIdentity.CreateRsaIdentity 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
建立 RSA 身分識別。
多載
CreateRsaIdentity(X509Certificate2) |
使用指定的 X.509 憑證建立 RSA 身分識別。 |
CreateRsaIdentity(String) |
使用指定的公開金鑰建立 RSA 身分識別。 |
備註
使用這個身分識別連接至端點的安全 WCF 用戶端,將確認伺服器提供的宣告是否包含用來建構這個身分識別之 RSA 公開金鑰的宣告。
這些靜態方法的其中一個方法會呼叫其建構函式 RsaEndpointIdentity,藉此建立 RsaEndpointIdentity 的執行個體。
CreateRsaIdentity(X509Certificate2)
使用指定的 X.509 憑證建立 RSA 身分識別。
public:
static System::ServiceModel::EndpointIdentity ^ CreateRsaIdentity(System::Security::Cryptography::X509Certificates::X509Certificate2 ^ certificate);
public static System.ServiceModel.EndpointIdentity CreateRsaIdentity (System.Security.Cryptography.X509Certificates.X509Certificate2 certificate);
static member CreateRsaIdentity : System.Security.Cryptography.X509Certificates.X509Certificate2 -> System.ServiceModel.EndpointIdentity
Public Shared Function CreateRsaIdentity (certificate As X509Certificate2) As EndpointIdentity
參數
- certificate
- X509Certificate2
X509Certificate2,其中包含 RSA 身分識別的憑證。
傳回
與指定之 EndpointIdentity 關聯的 RSA certificate
。
例外狀況
certificate
為 null
。
certificate
不是 RSA 憑證。
範例
下列程式碼將示範如何呼叫這個方法。
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;
備註
連線到具有此身分識別之端點的安全 WCF 用戶端會驗證服務器所提供的宣告是否包含宣告,其中包含從用來建構此身分識別之憑證取得的 RSA 公開金鑰。
這個靜態方法會呼叫其建構函式 RsaEndpointIdentity,藉此建立 RsaEndpointIdentity 的執行個體。
適用於
CreateRsaIdentity(String)
使用指定的公開金鑰建立 RSA 身分識別。
public:
static System::ServiceModel::EndpointIdentity ^ CreateRsaIdentity(System::String ^ publicKey);
public static System.ServiceModel.EndpointIdentity CreateRsaIdentity (string publicKey);
static member CreateRsaIdentity : string -> System.ServiceModel.EndpointIdentity
Public Shared Function CreateRsaIdentity (publicKey As String) As EndpointIdentity
參數
- publicKey
- String
RSA 身分識別的公開金鑰。
傳回
與指定之 EndpointIdentity 關聯的 RSA publicKey
。
例外狀況
publicKey
為 null
。
備註
使用這個身分識別連接至端點的安全 WCF 用戶端,將確認伺服器提供的宣告是否包含用來建構這個身分識別之 RSA 公開金鑰的宣告。
這個靜態方法會呼叫其建構函式 RsaEndpointIdentity,藉此建立 RsaEndpointIdentity 的執行個體。