2009-05-19 53 views
0

我有一个简单的Web服务,通​​过基于表单的身份验证处理安全性。基于WCF表单的身份验证通过Web应用程序 - 传递证书

WCFTestService.ServiceClient myService = new 
      WCFTestService.ServiceClient(); 
myService.ClientCredentials.UserName.UserName = "user"; 
myService.ClientCredentials.UserName.Password = "secret"; 
lblResult.Text = myService.GetData(1231); 
myService.Close(); 

我正在通过网络应用程序访问它。所以我想要做一次以上的事情,但是为了安全/性能,不必再做一次。我想是这样的下面,但因为我使用FormsAuthentication这不会工作...

//Obtain the authenticated user's Identity and impersonate the original caller 
using (((WindowsIdentity)HttpContext.Current.User.Identity).Impersonate()) 
{ 
    WCFTestService.ServiceClient myService2 = new WCFTestService.ServiceClient(); 
    lblResult.Text = "From Logged On Credentials"+myService2.GetData(1231); 
    myService2.Close(); 
} 

回答

1

你试图做的是建立你的客户和你的服务之间的“安全对话”。这是一个只适用于wsHttpBinding的概念 - 所以如果你没有使用特定的绑定,它将无法工作。

要建立安全会话,您需要在客户端和服务器的配置文件中设置一些特定的配置属性 - 您可以通过阅读文档(查找“establishSecurityContext”)或查看Michele Leroux Bustumante在MSDN上的优秀WCF screencast on security fundamentals

但真的:我不会建议通过一切手段使用安全会话。在正常情况下,使用每个通话服务是首选选项,每个服务通话重新进行身份验证的开销实际上可以忽略不计。

Marc