EndpointIdentity.CreateX509CertificateIdentity 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
建立 X509Certificate 身分識別。
多載
CreateX509CertificateIdentity(X509Certificate2) |
使用指定的憑證建立 X509Certificate 身分識別。 |
CreateX509CertificateIdentity(X509Certificate2, X509Certificate2Collection) |
使用指定的主要與支援憑證建立 X509Certificate 身分識別。 |
備註
您可根據是否有支援的憑證,選擇使用兩個建構函式的其中一個。
使用這個身分識別連線至端點的安全 WCF 用戶端,會確認伺服器提供的宣告是否包含用來建構這個身分識別之憑證指紋的宣告。
CreateX509CertificateIdentity(X509Certificate2)
使用指定的憑證建立 X509Certificate 身分識別。
public:
static System::ServiceModel::EndpointIdentity ^ CreateX509CertificateIdentity(System::Security::Cryptography::X509Certificates::X509Certificate2 ^ certificate);
public static System.ServiceModel.EndpointIdentity CreateX509CertificateIdentity (System.Security.Cryptography.X509Certificates.X509Certificate2 certificate);
static member CreateX509CertificateIdentity : System.Security.Cryptography.X509Certificates.X509Certificate2 -> System.ServiceModel.EndpointIdentity
Public Shared Function CreateX509CertificateIdentity (certificate As X509Certificate2) As EndpointIdentity
參數
- certificate
- X509Certificate2
X509Certificate2,其中包含身分識別的憑證。
傳回
與指定之 EndpointIdentity 關聯的 X509Certificate certificate
。
例外狀況
certificate
為 null
。
範例
下列程式碼將示範如何呼叫這個方法。
// This method creates a WSFederationHttpBinding.
public static WSFederationHttpBinding CreateWSFederationHttpBinding()
{
// Create an instance of the WSFederationHttpBinding.
WSFederationHttpBinding b = new WSFederationHttpBinding();
// Set the security mode to Message.
b.Security.Mode = WSFederationHttpSecurityMode.Message;
// Set the Algorithm Suite to Basic256Rsa15.
b.Security.Message.AlgorithmSuite = SecurityAlgorithmSuite.Basic256Rsa15;
// Set NegotiateServiceCredential to true.
b.Security.Message.NegotiateServiceCredential = true;
// Set IssuedKeyType to Symmetric.
b.Security.Message.IssuedKeyType = SecurityKeyType.SymmetricKey;
// Set IssuedTokenType to SAML 1.1.
b.Security.Message.IssuedTokenType = "http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.1#samlv1.1";
// Extract the STS certificate from the certificate store.
X509Store store = new X509Store(StoreName.TrustedPeople, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certs = store.Certificates.Find(X509FindType.FindByThumbprint, "cd 54 88 85 0d 63 db ac 92 59 05 af ce b8 b1 de c3 67 9e 3f", false);
store.Close();
// Create an EndpointIdentity from the STS certificate.
EndpointIdentity identity = EndpointIdentity.CreateX509CertificateIdentity(certs[0]);
// Set the IssuerAddress using the address of the STS and the previously created EndpointIdentity.
b.Security.Message.IssuerAddress = new EndpointAddress(new Uri("http://localhost:8000/sts/x509"), identity);
// Set the IssuerBinding to a WSHttpBinding loaded from config
b.Security.Message.IssuerBinding = new WSHttpBinding("Issuer");
// Set the IssuerMetadataAddress using the metadata address of the STS and the previously created EndpointIdentity.
b.Security.Message.IssuerMetadataAddress = new EndpointAddress(new Uri("http://localhost:8001/sts/mex"), identity);
// Create a ClaimTypeRequirement.
ClaimTypeRequirement ctr = new ClaimTypeRequirement("http://example.org/claim/c1", false);
// Add the ClaimTypeRequirement to ClaimTypeRequirements.
b.Security.Message.ClaimTypeRequirements.Add(ctr);
// Return the created binding.
return b;
}
}
備註
使用這個身分識別連線至端點的安全 WCF 用戶端,會確認伺服器提供的宣告是否包含用來建構這個身分識別之憑證指紋的宣告。
這個 static
方法會使用 X509CertificateEndpointIdentity 做為輸入參數來呼叫其建構函式 X509CertificateEndpointIdentity,藉此建立 certificate
的執行個體。
適用於
CreateX509CertificateIdentity(X509Certificate2, X509Certificate2Collection)
使用指定的主要與支援憑證建立 X509Certificate 身分識別。
public:
static System::ServiceModel::EndpointIdentity ^ CreateX509CertificateIdentity(System::Security::Cryptography::X509Certificates::X509Certificate2 ^ primaryCertificate, System::Security::Cryptography::X509Certificates::X509Certificate2Collection ^ supportingCertificates);
public static System.ServiceModel.EndpointIdentity CreateX509CertificateIdentity (System.Security.Cryptography.X509Certificates.X509Certificate2 primaryCertificate, System.Security.Cryptography.X509Certificates.X509Certificate2Collection supportingCertificates);
static member CreateX509CertificateIdentity : System.Security.Cryptography.X509Certificates.X509Certificate2 * System.Security.Cryptography.X509Certificates.X509Certificate2Collection -> System.ServiceModel.EndpointIdentity
Public Shared Function CreateX509CertificateIdentity (primaryCertificate As X509Certificate2, supportingCertificates As X509Certificate2Collection) As EndpointIdentity
參數
- primaryCertificate
- X509Certificate2
X509Certificate2,其中包含身分識別的主要憑證。
- supportingCertificates
- X509Certificate2Collection
X509Certificate2Collection,其中包含身分識別的支援憑證。
傳回
使用這個身分識別連線至端點的安全 WCF 用戶端,會確認伺服器提供的宣告是否包含用來建構這個身分識別之憑證指紋的宣告。
與指定 primaryCertificate
和 supportingCertificates
相關聯的 X509Certificate EndpointIdentity 。
例外狀況
primaryCertificate
或 supportingCertificates
為 null
。
備註
這個靜態方法會使用 X509CertificateEndpointIdentity 和 X509CertificateEndpointIdentity 當做輸入參數來呼叫其建構函式 primaryCertificate
,藉此建立 supportingCertificates
的執行個體。