繁体   English   中英

WCF安全异常

[英]WCF security exception

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

我有这个到现在:服务:

 WSHttpBinding binding = new WSHttpBinding(SecurityMode.Transport);
 binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
 ServiceHost svh = new ServiceHost(Type.GetType(MyClass);       
 svh.AddServiceEndpoint(IMyClass, binding, "https://localhost:9090/ServiceTest");                       
 ServiceMetadataBehavior sb = new ServiceMetadataBehavior();
 sb.HttpsGetEnabled = true;
 sb.HttpsGetUrl = new Uri("https://localhost:9090/ServiceTest");
 svh.Description.Behaviors.Add(sb);
 svh.Open();

客户:

 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();

我首先启动控制台应用程序......我的所有服务都是开放的。
但是当我从webapplication调用服务中的方法时,我得到一个异常说:

 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.

当我用Google搜索...我发现我需要在iis上设置ssl证书...但我的服务托管在控制台应用程序上......那我该如何设置这些证书? 此外,如何设置用户名和密码以允许使用该服务?

看看这里

您需要设置证书。

@Aliostad答案+1。

另一个选择是尽可能使用不同的绑定。 默认情况下,您可以使用NetTcpBinding获取传输安全性,而无需设置证书。 这种方法的工作要少得多。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM