我有一个控制台应用程序,用于启动(打开)我的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证书...但我的服务托管在控制台应用程序上......那我该如何设置这些证书?此外,如何设置用户名和密码以允许使用服务?
答案 0 :(得分:2)
看看here。
您需要设置证书。
答案 1 :(得分:0)
+1。
另一个选择是尽可能使用不同的绑定。默认情况下,您可以使用NetTcpBinding获取传输安全性,而无需设置证书。这种方法的工作要少得多。