2009-10-28 104 views
3

我在同一台计算机上有两个WCF服务。一个是出版商,一个是听众。WCF:由于身份验证失败,无法满足安全令牌请求

发布者基于和端点动态创建代理。我配置代理在这样的代码:

  WSHttpBinding binding = new WSHttpBinding(SecurityMode.Message, true); 
      binding.Security.Message.NegotiateServiceCredential = true; 
      binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows; 
      binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None; 
      binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows; 
      binding.Security.Message.EstablishSecurityContext = true; 
      binding.ReliableSession.Enabled = true; 
      binding.TransactionFlow = true; 
      return binding; 

然后......

  Binding binding = GetBindingFromAddress(address); 

      ChannelFactory<T> factory = new ChannelFactory<T>(binding); 
      factory.Credentials.UserName.UserName = "an account on the machine"; 
      factory.Credentials.UserName.Password = "a password for that account"; 

      T proxy = factory.CreateChannel(new EndpointAddress(address)); 

当我去让我的电话,我收到上述错误。这是我的监听器的配置文件:

<service behaviorConfiguration="MEX Enabled" name="InvoiceSubscriber"> 
<endpoint binding="wsHttpBinding" 
      bindingConfiguration="ReliableTransactionalHTTP" 
      contract="AtlanticBT.SubscriptionService.Contracts.v1.IAtlanticEvents"> 
<identity> 
    <dns value="localhost" /> 
</identity> 
</endpoint> 

 <bindings> 
     <wsHttpBinding> 
      <binding name="ReliableTransactionalHTTP" transactionFlow="true"> 
       <reliableSession enabled="true"/> 
     <security mode="Message"> 
     <transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/> 
     <message clientCredentialType="Windows" negotiateServiceCredential="true" 
       algorithmSuite="Default" establishSecurityContext="true"/> 
     </security> 
      </binding> 
    </wsHttpBinding> 
    </bindings> 

我检查我的所有ACL在承载服务的目录和他们似乎是正确的。 IIS安全性设置为匿名访问和Windows身份验证。

因此,如果我明确地设置代码中的凭据,为什么我的听众不能进行身份验证?

+0

请求本身可能格式错误。使用Fiddler检查原始请求/响应,以确保您传递的是真正正确的请求。 http://www.fiddler2.com/fiddler2/ – 2009-10-28 21:31:44

+0

Ahh提琴手...我忘了那个小窍门。我会尝试看看。我还必须制定我的身份验证方案。谢谢! – Daryl 2009-10-29 13:20:50

回答

16

首先,此消息通常意味着机器不在同一个域中,因此无法使用Windows安全性进行通信。这两台服务器在同一个域上吗?

其次,您已将端点配置为使用Windows安全性。您不仅在消息级别使用Windows安全性,而且在传输级别使用Windows安全性。两者似乎都是过度杀伤,你可能只是想做运输。第三,您配置的所有内容都说“我想使用Windows身份验证”,但是您要设置ClientCredentials的UsernameClientCredentials属性。这些属性仅用于用户名令牌安全性,而不是Windows。 Windows安全性将采用当前线程的身份并将其转发。

假设你的意图是使用Windows的安全性,那么您可能需要:

  1. 运行在你想让它与用户为进行通信的单一的Windows标识您的出版商过程。
  2. 发行过程中使用模拟来改变每个呼叫的安全上下文(考虑WindowsIdentity.Impersonate获取更多信息)

现在你在技术上做#1,即使你认为你正在做#2设置用户名/密码属性,因为它们被忽略。

最后,这里有一些好的文档如何设置你的绑定不同类型的Windows身份验证方案:


除此之外,我不确定还有什么我可以放弃来自你的更多信息。如果您修改您的问题以提供更多信息/回答我的一些问题,我将很乐意修改我的答案,希望能够使其更有用。

+0

德鲁 - 非常感谢您的回复。我将准备好您提到的文章,并在当天晚些时候回复。 我的意图是使用Windows身份验证。这些服务位于同一个域中运行的同一台计算机上。 谢谢! – Daryl 2009-10-29 13:19:30

+0

我有两个场景来解释。这项服务是否需要服务,我一定希望Windows安全。我只设置了Windows身份验证(允许ThreadCurrentPrincipal成为调用者)并删除了ClientCredentials。 对于非Windows客户端,我将探索使用用户名令牌安全性或基于证书的安全性。我现在在路上感谢您的帖子......感谢他们非常有帮助的文章。 Daryl – Daryl 2009-11-02 17:30:26

相关问题