src/System.Private.ServiceModel/tools/IISHostedWcfService/App_code/testhosts/TcpCertificateWithSubjectCanonicalNameLocalhostTestServiceHost.cs (33 lines of code) (raw):

// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using System; using System.Security.Cryptography.X509Certificates; using System.ServiceModel; using System.ServiceModel.Channels; namespace WcfService { [TestServiceDefinition(Schema = ServiceSchema.NETTCP, BasePath = "TcpCertificateWithSubjectCanonicalNameLocalhost.svc")] public class TcpCertificateWithSubjectCanonicalNameLocalhostTestServiceHost : TestServiceHostBase<IWcfService> { protected override string Address { get { return "tcp-server-subject-cn-localhost-cert"; } } protected override Binding GetBinding() { NetTcpBinding binding = new NetTcpBinding() { PortSharingEnabled = false }; binding.Security.Mode = SecurityMode.Transport; binding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None; return binding; } protected override void ApplyConfiguration() { base.ApplyConfiguration(); string certThumprint = TestHost.CertificateFromFriendlyName(StoreName.My, StoreLocation.LocalMachine, "WCF Bridge - TcpCertificateWithSubjectCanonicalNameLocalhostResource").Thumbprint; this.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindByThumbprint, certThumprint); } public TcpCertificateWithSubjectCanonicalNameLocalhostTestServiceHost(params Uri[] baseAddresses) : base(typeof(WcfService), baseAddresses) { } } }