我上下打量,我似乎无法找到一种方法来让一个简单的WCF服务(basicHttpBinding
或wsHttpBinding
)对这种配置进行身份验证:
<authentication mode="Forms">
<forms cookieless="UseCookies">
<credentials passwordFormat="Clear">
<user name="test" password="pass"/>
</credentials>
</forms>
</authentication>
基本上,我想硬编码一个简单的用户/传递(不要问为什么),并确保我的WCF服务使用它。
在客户端,我有这个:
client.ClientCredentials.UserName.UserName = "test";
client.ClientCredentials.UserName.Password = "pass";
但凭据似乎没有传递。 HttpContext.Current.User.Identity
永远不会在WCF端进行身份验证。
我尝试使用以下设置尝试使用无,传输,消息等所有内容...但只有None
似乎让服务运行(但没有发送/使用凭据)。其他设置似乎需要X509证书(正如我在this great example中找到的那样)。
<wsHttpBinding>
<binding name="userHttp">
<security mode="None">
<message clientCredentialType="UserName"/>
</security>
</binding>
</wsHttpBinding>
所以,总而言之...我想创建一个非常简单的WCF服务(通过HTTP运行 - 而不是HTTPS),甚至更简单的纯文本用户名/密码身份验证。应该可以,但我已经迷路了。最好的解决方案是尊重<user />
条目,但我对任何其他简单的实现感到满意。它不需要使用cookie。就我而言,它也可以在每个服务方法调用上发送用户名/密码。
答案 0 :(得分:2)
如果您想在没有ssl的情况下发送消息级别的用户/传递,请使用ClearUsernameBinding。如果您想在传输级别使用相同的内容,请使用TransportCredentialOnly。
<binding name="BasicHttpEndpointBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>