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 (string subjectName, System.Security.Cryptography.X509Certificates.StoreLocation storeLocation, System.Security.Cryptography.X509Certificates.StoreName 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

.NET 8 (package-provided) och andra versioner
Produkt Versioner
.NET Core 1.0, Core 1.1, 8 (package-provided)
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

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, object findValue);

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

.NET 8 (package-provided) och andra versioner
Produkt Versioner
.NET Core 1.0, Core 1.1, 8 (package-provided)
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)