C# WCF安全例外

C# WCF安全例外,c#,wcf,C#,Wcf,我有一个控制台应用程序,用于启动(打开)我的wcf服务 我有一个使用这些服务的web应用程序。 如何通过身份验证实现传输级安全性 到目前为止,我有这样的想法: 服务: 客户: WSHttpBinding binding = new WSHttpBinding(SecurityMode.Transport); binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None; EndpointIde

我有一个控制台应用程序,用于启动(打开)我的wcf服务 我有一个使用这些服务的web应用程序。 如何通过身份验证实现传输级安全性

到目前为止,我有这样的想法: 服务:

客户:

 WSHttpBinding binding = new WSHttpBinding(SecurityMode.Transport);
 binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
 EndpointIdentity endpointIdentity = EndpointIdentity.CreateDnsIdentity("localhost");
 EndpointAddress endPoint = new EndpointAddress(new Uri("https://localhost:9090/ServiceTest"), endpointIdentity, new AddressHeaderCollection());    
 ChannelFactory<T> engineFactory = new ChannelFactory<T>(binding, endPoint);
 T MyService = engineFactory.CreateChannel();
当我在谷歌上搜索时。。。我发现我需要在iis上设置ssl证书。。。但我的服务托管在控制台应用程序上。。。那么如何设置这些证书?此外,如何为设置用户名和密码以允许使用该服务?

请查看


您需要设置您的证书。

+1在@Aliostad答案上

您的另一个选择是使用不同的绑定(如果可以的话)。例如,您可以在默认情况下使用获得传输安全性,而无需设置证书。这种方法的工作量要小得多。

这种方法也有帮助!
 WSHttpBinding binding = new WSHttpBinding(SecurityMode.Transport);
 binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
 EndpointIdentity endpointIdentity = EndpointIdentity.CreateDnsIdentity("localhost");
 EndpointAddress endPoint = new EndpointAddress(new Uri("https://localhost:9090/ServiceTest"), endpointIdentity, new AddressHeaderCollection());    
 ChannelFactory<T> engineFactory = new ChannelFactory<T>(binding, endPoint);
 T MyService = engineFactory.CreateChannel();
 An error occurred while making the HTTP request to 
 https://localhost:9090/ServiceTest. This could be due to the fact that the
 server certificate is not configured properly with HTTP.SYS in the HTTPS case. This 
 could also be caused by a mismatch of the security binding between the client and the 
 server.