2011-04-15 277 views
0

我有一個控制檯應用程序,用於啓動(打開)我的wcf服務 我有一個使用這些服務的Web應用程序。 我如何使用身份驗證實現傳輸級安全性?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. 

當我GOOGLE了......我發現我需要設置在IIS上的SSL證書......但我的服務託管在控制檯應用程序上......那麼我如何設置這些證書?此外,我如何設置用戶名和密碼以允許使用該服務?

回答

2

看一看here

您需要設置您的證書。

+0

這個人也可以幫忙!https://notgartner.wordpress.com/2007/09/06/using-certificate-based-authentication-and-protection-with-windows-communication-foundation-wcf/ – 2011-04-15 12:43:08

0

@Aliostad答案+1。

另一種選擇是使用不同的綁定(如果可以的話)。例如,您可以通過默認的NetTcpBinding獲得傳輸安全性,而無需設置證書。這種方法會少得多。