【发布时间】:2011-04-15 21:14:02
【问题描述】:
我有一个控制台应用程序,用于启动(打开)我的 wcf 服务 我有一个使用这些服务的网络应用程序。 如何通过身份验证实现传输级安全性?
到目前为止,我有这个: 服务:
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();
我首先启动控制台应用程序...并且我的所有服务都已打开。
但是当我从 web 应用程序调用服务中的方法时,我得到一个异常说:
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.
当我用谷歌搜索...我发现我需要在 iis 上设置 ssl 证书...但我的服务托管在控制台应用程序上...那么我该如何设置这些证书?此外,如何设置用户名和密码以允许使用该服务?
【问题讨论】: