如何使用UserNamePasswordValidator可选? [英] How do I make the use of UserNamePasswordValidator optional?
问题描述
我的服务部分不要求用户进行身份验证,但由于连接管道被引导到UserNamePasswordValidator,我无法在不设置用户名称凭据的情况下访问我的服务的某些功能。我怎么能
克服这个问题?我是否必须添加另一个端点才能使用不需要进行身份验证的功能?
My service partially doesn't require the user to be authenticated but as the connection pipe is channeled to UserNamePasswordValidator I'm not able to access some functionality of my service without setting at least the user's name credential. How can I overcome this problem? Do I have to add another endpoint just to use the functions that doesn't require to be authenticated?
非常感谢。
推荐答案
以下是使用UserNamePassword验证的步骤 - 以下内容摘自" WCF - 使用用户名和密码验证客户端,您可以参考此文章以获取更多参考:
Here is the steps to follow to use the UserNamePassword Validation - Following is extracted from 'WCF - Authenticate the client using User name and Password', you can refer this article for more reference:
- 添加 wsHttpBinding Element 到 < bindings> 部分Web.config文件的
。 - 将 绑定 元素添加到 wsHttpBinding 元素并将 configurationName 属性设置为
a价值适合您的需求。 - 添加 < security> < wsHttpBinding> 元素绑定并设置 模式 将
归因于" Message" ;
。
- 添加 < message> for< security> for< wsHttpBinding> 到 安全性 绑定,
并将 clientCredentialType 属性设置为" UserName"
,如下面的代码所示:
- Add a wsHttpBinding Element to the <bindings> section of the Web.config file.
- Add a binding element to the wsHttpBinding element and set the configurationName attribute to a value appropriate to your needs.
- Add a <security> for <wsHttpBinding> element to the binding and set the mode attribute
to
"Message"
. - Add a <message> for <security> for <wsHttpBinding> to the security binding,
and set the clientCredentialType attribute to
"UserName"
, as shown in the following code:
< system.serviceModel>
< bindings>
< wsHttpBinding>
< binding name =” Binding1″>
< security mode =” Message”>
< ; message clientCredentialType =” UserName” />
< / security>
< / binding>
< / wsHttpBinding>
< / bindings>
< /system.serviceModel>
-
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name=”Binding1″>
<security mode=”Message”>
<message clientCredentialType=”UserName”/>
</security>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
将用户名和密码发送到服务的客户端代码
- 创建客户端类的实例,如下所示代码。
- Create an instance of the client class as shown in the following code.
CalculatorClient client = new CalculatorClient(" default");
所示。
client.ClientCredentials.UserName.Password =" Your Password" ;;
client.ClientCredentials.UserName.UserName ="您的用户名" ;;
double value1 = client.Add(100,15.99);
希望这会有所帮助......
-
祝你好运...
这篇关于如何使用UserNamePasswordValidator可选?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!