我有一个 WCF 服务,需要接收客户端凭据,并根据我的身份验证方法维护某种基于角色的数据。
客户端将驻留在许多不同的系统上,因此,每个客户端将具有唯一的用户 ID 和密码。
我正在使用 basicHttpBinding 并阅读了一些文章,例如这篇文章, http://nirajrules.wordpress.com/2009/05/22/username-over-https-custombinding-with-wcf%E2%80%99s -channelfactory-interface/,描述该过程。
所以我正在寻找的是是否有人配置了一个完整的客户端/服务器来查看,以便我可以从中得出我自己的解决方案。
我想做的是在每个请求的标头中传递用户名和密码,在失败时传回某种 SecurityTokenValidationException,或者在通过时继续。
谢谢。
更新
我在客户端和服务器上都使用具有以下配置的 wsHttpbinding:
<wsHttpBinding>
<binding name="wsHttpEndpointBinding" >
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="Basic" />
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
并且从客户端调用服务器如下:
ServiceReference1.ServiceClient myClient = new ServiceReference1.ServiceClient();
myClient.ClientCredentials.UserName.UserName = "billuser";
myClient.ClientCredentials.UserName.Password = "mypassword";
Response.Write("Data from WCF Service: " + myClient.GetData(1));
我想我需要一点帮助来连接服务器上的 CustomUsernamePasswordValidator,因为我仍然收到“...无法激活”。错误。