如何使用UserNamePasswordValidator可选? [英] How do I make the use of UserNamePasswordValidator optional?

查看:101
本文介绍了如何使用UserNamePasswordValidator可选?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的服务部分不要求用户进行身份验证,但由于连接管道被引导到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:

 


  1. 添加  wsHttpBinding Element     < bindings>   部分Web.config文件的
  2.   绑定   元素添加到  wsHttpBinding   元素并将  configurationName   属性设置为
    a价值适合您的需求。
  3. 添加  < security> < wsHttpBinding>   元素绑定并设置  模式  
    归因于  " Message" ;
  4. 添加  < message> for< security> for< wsHttpBinding>     安全性   绑定,
    并将  clientCredentialType   属性设置为  " UserName" ,如下面的代码所示:
  1. Add a wsHttpBinding Element to the <bindings> section of the Web.config file.
  2. Add a binding element to the wsHttpBinding element and set the configurationName attribute to a value appropriate to your needs.
  3. Add a <security> for <wsHttpBinding> element to the binding and set the mode attribute to "Message".
  4. 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>






    将用户名和密码发送到服务的客户端代码



  1. 创建客户端类的实例,如下所示代码。
  1. Create an instance of the client class as shown in the following code.

    CalculatorClient client = new CalculatorClient(" default");


  • 设置    UserNamePasswordClientCredential   类的span> 密码   属性密码。可以从客户端对象访问该类,如下面的代码
    所示。

  • Set the Password property of the UserNamePasswordClientCredential class to the password. The class is accessible from the client object, as shown in the following code.


      client.ClientCredentials.UserName.Password =" Your Password" ;;


  • 设置  用户名   属性为用户的用户名。

  • Set the UserName property to the user’s user name.


      client.ClientCredentials.UserName.UserName ="您的用户名" ;;


  • 调用服务的方法。

  • Call the methods of the service.


      double value1 = client.Add(100,15.99);







      希望这会有所帮助......



    1.  
      祝你好运...



    这篇关于如何使用UserNamePasswordValidator可选?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆