Muokkaa

Jaa


X509CertificateRecipientClientCredential.SetDefaultCertificate Method

Definition

Specifies the default certificate to use for the service.

Overloads

SetDefaultCertificate(String, StoreLocation, StoreName)

Specifies the default certificate to use for the service. For bindings that use certificate-based message security, this certificate is used to encrypt messages to the service and is expected to be used by the service for signing replies to the client.

SetDefaultCertificate(StoreLocation, StoreName, X509FindType, Object)

Specifies the default certificate to use for the service. For bindings that use certificate-based message security, this certificate is used to encrypt messages to the service and is expected to be used by the service for signing replies to the client.

Remarks

These methods get a certificate from the store in the specified location that matches specified parameters.

For bindings that use certificate-based message security, this certificate is used to encrypt messages to the service and is expected to be used by the service for signing replies to the client.

SetDefaultCertificate(String, StoreLocation, StoreName)

Source:
X509CertificateRecipientClientCredential.cs
Source:
X509CertificateRecipientClientCredential.cs

Specifies the default certificate to use for the service. For bindings that use certificate-based message security, this certificate is used to encrypt messages to the service and is expected to be used by the service for signing replies to the client.

public:
 void SetDefaultCertificate(System::String ^ subjectName, System::Security::Cryptography::X509Certificates::StoreLocation storeLocation, System::Security::Cryptography::X509Certificates::StoreName storeName);
public void SetDefaultCertificate (string subjectName, System.Security.Cryptography.X509Certificates.StoreLocation storeLocation, System.Security.Cryptography.X509Certificates.StoreName storeName);
member this.SetDefaultCertificate : string * System.Security.Cryptography.X509Certificates.StoreLocation * System.Security.Cryptography.X509Certificates.StoreName -> unit
Public Sub SetDefaultCertificate (subjectName As String, storeLocation As StoreLocation, storeName As StoreName)

Parameters

subjectName
String

The subject distinguished name.

storeLocation
StoreLocation

The location of the certificate store that the service uses to obtain the service certificate.

storeName
StoreName

The name of the X.509 certificate store to open.

Exceptions

subjectName is null.

Attempted to set when the credential is read-only.

Examples

The following code uses this method to specify an X.509 certificate to use.

public void snippet23(CalculatorClient cc)
{
    X509CertificateRecipientClientCredential rcc = cc.ClientCredentials.ServiceCertificate;
    rcc.SetDefaultCertificate("http://fabrikam.com/sts",
                             StoreLocation.CurrentUser,
                             StoreName.TrustedPeople);
}

Remarks

This method gets a certificate from the store in the specified location that matches the subjectName parameter.

Values for storeLocation are included in the StoreLocation enumeration:

  • LocalMachine: the certificate store assigned to the local machine.

  • CurrentUser: the certificate store used by the current user (default).

If the application is running under a system account, then the certificate is typically in LocalMachine. If the application is running under a user account, then the certificate is typically in CurrentUser.

Values for storeName are included in the StoreName enumeration.

Applies to

SetDefaultCertificate(StoreLocation, StoreName, X509FindType, Object)

Source:
X509CertificateRecipientClientCredential.cs
Source:
X509CertificateRecipientClientCredential.cs

Specifies the default certificate to use for the service. For bindings that use certificate-based message security, this certificate is used to encrypt messages to the service and is expected to be used by the service for signing replies to the client.

public:
 void SetDefaultCertificate(System::Security::Cryptography::X509Certificates::StoreLocation storeLocation, System::Security::Cryptography::X509Certificates::StoreName storeName, System::Security::Cryptography::X509Certificates::X509FindType findType, System::Object ^ findValue);
public void SetDefaultCertificate (System.Security.Cryptography.X509Certificates.StoreLocation storeLocation, System.Security.Cryptography.X509Certificates.StoreName storeName, System.Security.Cryptography.X509Certificates.X509FindType findType, object findValue);
member this.SetDefaultCertificate : System.Security.Cryptography.X509Certificates.StoreLocation * System.Security.Cryptography.X509Certificates.StoreName * System.Security.Cryptography.X509Certificates.X509FindType * obj -> unit
Public Sub SetDefaultCertificate (storeLocation As StoreLocation, storeName As StoreName, findType As X509FindType, findValue As Object)

Parameters

storeLocation
StoreLocation

The location of the certificate store the service uses to obtain the service certificate.

storeName
StoreName

The name of the X.509 certificate store to open.

findType
X509FindType

The type of X.509 search to be executed.

findValue
Object

The value to search for in the X.509 certificate store.

Exceptions

findValue is null.

Attempted to set when the credential is read-only.

Examples

The following code uses this method to specify an X.509 certificate to use.

public void snippet22(CalculatorClient cc)
{
    X509CertificateRecipientClientCredential rcc = cc.ClientCredentials.ServiceCertificate;
    rcc.SetDefaultCertificate(StoreLocation.CurrentUser,
                             StoreName.TrustedPeople,
                             X509FindType.FindBySubjectName,
                             "FabrikamSTS");
}

Remarks

This method gets a certificate from the store in the specified location that matches the findType and findValue parameters.

Values for storeLocation are included in the StoreLocation enumeration:

  • LocalMachine: the certificate store assigned to the local machine.

  • CurrentUser: the certificate store used by the current user (default).

If the application is running under a system account, then the certificate is typically in LocalMachine. If the application is running under a user account, then the certificate is typically in CurrentUser.

Values for storeName are included in the StoreName enumeration.

Values for findType are included in the X509FindType enumeration.

The most commonly used enumeration is FindBySubjectName, which does a case-insensitive search on the subject name of certificates in the specified store. This can be an imprecise search. If no certificates or multiple certificates that match the criteria are found, an InvalidOperationException is thrown.

Applies to