【问题标题】:WCF security exceptionWCF 安全异常
【发布时间】: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 证书...但我的服务托管在控制台应用程序上...那么我该如何设置这些证书?此外,如何设置用户名和密码以允许使用该服务?

【问题讨论】:

    标签: c# wcf


    【解决方案1】:

    看看here。

    您需要设置您的证书。

    【讨论】:

    【解决方案2】:

    @Aliostad 回答 +1。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-29
      • 1970-01-01
      • 1970-01-01
      • 2011-02-15
      • 2016-06-16
      • 1970-01-01
      • 1970-01-01
      • 2013-05-02
      相关资源
      最近更新 更多