如何创建行为类似于匿名HTTPS会话的WCF net.tcp连接?

时间:2010-02-23 13:21:12

标签: c# wcf-binding

我正在尝试使用服务器上的证书建立WCF连接,以验证服务器并加密客户端和服务器之间的数据。

我已经像这样配置了服务器端:

  //  Create the Service
  serviceHost = new ServiceHost(typeof(CIncommingWCFObject));

  //  Now Create the Binding
  NetTcpBinding tcpb = new NetTcpBinding();

  //  Set  the Security to use a certificate for both enctyption and signing...
  tcpb.Security.Mode = SecurityMode.TransportWithMessageCredential;
  tcpb.Security.Message.ClientCredentialType = MessageCredentialType.Certificate;
  tcpb.Security.Transport.ClientCredentialType = TcpClientCredentialType.None;
  tcpb.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSign;
  serviceHost.AddServiceEndpoint(typeof(IDatabaseServer), tcpb, Params.Uri);

  //  Define the Servers Certificate
  serviceHost.Credentials.ServiceCertificate.SetCertificate(StoreLocation.CurrentUser, StoreName.My, X509FindType.FindBySubjectName, Params.CertificateName);

  //  And then open the socket...
  serviceHost.Open();

允许服务打开。

但是,我尝试定义可以连接到此端的客户端失败了。

有人能让我朝着正确的方向前进吗?

亲切的问候,

MIC

1 个答案:

答案 0 :(得分:0)

这篇文章可能有所帮助:

Fundamentals of WCF Security