在wcf中使用自定义的用户名和密码验证方式

https://msdn.microsoft.com/en-us/library/aa702565.aspx

http://www.codeproject.com/Articles/96028/WCF-Service-with-custom-username-password-authenti

To configure a service to use a custom user name and password validator

  1. Configure a binding that uses message security over any transport or transport-level security over HTTP(S).

    When using message security, add one of the system-provided bindings, such as a <wsHttpBinding>, or a <customBinding> that supports message security and the UserName credential type.

    When using transport-level security over HTTP(S), add either the <wsHttpBinding> or <basicHttpBinding>, a <netTcpBinding> or a <customBinding> that uses HTTP(S) and the Basic authentication scheme.

    Note

    When .NET Framework version 3.5 or later is used, you can use a custom username and password validator with message and transport security. With WinFX, a custom username and password validator can only be used with message security.

    Tip

    For more information on using <netTcpBinding> in this context, see <security> of <netTcpBinding>

    1. In the configuration file, under the <system.serviceModel> element, add a <bindings> element.

    2. Add a <wsHttpBinding> or <basicHttpBinding> element to the bindings section. For more information about creating an WCF binding element, see How to: Specify a Service Binding in Configuration.

    3. Set the mode attribute of the <security> of <wsHttpBinding> or <security> of <basicHttpBinding> to Message, Transport, or TransportWithMessageCredential.

    4. Set the clientCredentialType attribute of the <message> of <wsHttpBinding> or <transport> of <wsHttpBinding>.

如果第3步使用的是Security是Message,那么就设置MessageSecurity的MessageClientCredentialType为UserName

When using message security, set the clientCredentialType attribute of the <message> of <wsHttpBinding> to UserName.

When using transport-level security over HTTP(S), set the clientCredentialType attribute of the <transport> of <wsHttpBinding> or <transport> of <basicHttpBinding> to Basic.

Note

When a WCF service is hosted in Internet Information Services (IIS) using transport-level security and the UserNamePasswordValidationMode property is set to Custom, the custom authentication scheme uses a subset of Windows authentication. That is because in this scenario, IIS performs Windows authentication prior to WCF invoking the custom authenticator.

For more information about creating an WCF binding element, see How to: Specify a Service Binding in Configuration.

The following example shows the configuration code for the binding.

<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="Binding1">
<security mode="Message">
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>

netTcpBinding的security的Mode属性,可以设置为4种类型,选择Message

 
如果Mode设置为Message的话,那么就需要设置MessageSecurity的MessageClientCredentialType为UserName
如果Mode设置为Transport的话,那么就需要设置TransportSecurity的TransportClientCredentialType

2.Configure a behavior that specifies that a custom user name and password validator is used to validate user name and password pairs for incoming UserNameSecurityToken security tokens.

  1. As a child to the <system.serviceModel> element, add a <behaviors> element.

  2. Add a <serviceBehaviors> to the <behaviors> element.

  3. Add a <behavior> of <serviceBehaviors> element and set the name attribute to an appropriate value.

  4. Add a <serviceCredentials> to the <behavior> of <serviceBehaviors> element.

  5. Add a <userNameAuthentication> to the <serviceCredentials>.

  6. Set the userNamePasswordValidationMode to Custom.

    Important

    If the userNamePasswordValidationMode value is not set, WCF uses Windows authentication instead of the custom user name and password validator.

  7. Set the customUserNamePasswordValidatorType to the type that represents your custom user name and password validator.

The following example shows the <serviceCredentials> fragment to this point.

<serviceCredentials>

<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Microsoft.ServiceModel.Samples.CalculatorService.CustomUserNameValidator, service" />

</serviceCredentials>


How to: Use a Custom User Name and Password Validator(WCF)的更多相关文章

  1. How to: Use a Custom User Name and Password Validator

    在wcf中使用自定义的用户名和密码验证方式 https://msdn.microsoft.com/en-us/library/aa702565.aspx http://www.codeproject. ...

  2. 【ASP.NET Identity系列教程(一)】ASP.NET Identity入门

    注:本文是[ASP.NET Identity系列教程]的第一篇.本系列教程详细.完整.深入地介绍了微软的ASP.NET Identity技术,描述了如何运用ASP.NET Identity实现应用程序 ...

  3. P6 Professional Installation and Configuration Guide (Microsoft SQL Server Database) 16 R1

    P6 Professional Installation and Configuration Guide (Microsoft SQL Server Database) 16 R1       May ...

  4. 优秀的PHP开源项目集合

    包管理Package Management Package Management Related 框架 框架组件 微框架Micro Frameworks 内容管理系统Content Managemen ...

  5. SSL构建单双向https认证

    1.  SSL基本介绍 我们常常在使用网上银行时看到的连接都是以“https”开始的,那么这个https是什么呢?这其实是表示目前连接使用了SSL进加密,能保证客户端到服务器端的通信都在被保护起来,那 ...

  6. PHP框架、库和软件资源大全(整理篇)

    php的资料 https://github.com/ziadoz/awesome-php Awesome PHP A curated list of amazingly awesome PHP lib ...

  7. Bootstrap风格登录界面设计样例

    参考:http://bootsnipp.com/tags/login Register Page   127.8K 187 Modal Login with jQuery Effects   159. ...

  8. ios swift模仿qq登陆界面,xml布局

    给大家推荐两个学习的地址: 极客学院的视频:http://www.jikexueyuan.com/path/ios/ 一个博客:http://blog.csdn.net/lizhongfu2013/a ...

  9. FNDCPASS Troubleshooting Guide For Login and Changing Applications Passwords

    In this Document   Goal   Solution   1. Error Starting Application Services After Changing APPS Pass ...

随机推荐

  1. [LeetCode] 461. Hamming Distance(位操作)

    传送门 Description The Hamming distance between two integers is the number of positions at which the co ...

  2. mac安装pip并升级pip版本

      最近想安装inchat,直接使用命令pip install install,结果提示 使用提示中的命令升级,结果提示找不到pip.很郁闷,明明有pip,结果一升级还给升没了.最后用的是这个方法完美 ...

  3. GD Library extension not available

    在后台文章上传封面时,遇到了这样一个错误 GD Library extension not available with this PHP installation Ubuntu Nginx 自己在本 ...

  4. [BZOJ4151]The Cave

    Solution: ​ 假设现在在点1,有许多形如 (x, y, z) 的限制条件,那么对于一组限制,必须先走到 x, y 的 \(\frac{z-dis(x, y)}{2}\) 级祖先,叫这些点为限 ...

  5. from、includes、indexOf

    from.includes.indexOf:https://blog.csdn.net/j59580/article/details/53897630?utm_source=blogxgwz1 语法 ...

  6. CSU 1092 Barricade

    1092: Barricade Time Limit: 1 Sec  Memory Limit: 32 MBSubmit: 240  Solved: 71[Submit][Status][Web Bo ...

  7. 表单验证之在a标签跳转之前执行其他操作(DOM与$两种实现方式)

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. Iplimage versus Mat

    我们可能经常面临这样的困惑,Iplimage和Mat这两种数据结构,我们应该用哪一种数据结构. Iplimage一开始就存在opencv库之中,他来源于Intel的另外一个函数库Intel Image ...

  9. 8VC Venture Cup 2017 - Elimination Round - A

    题目链接:http://codeforces.com/contest/755/problem/A 题意:给定一个正整数N,问你是否存在一个数M使得N*M+1不是素数(M的范围在[1,1000]). 思 ...

  10. (ACM模板)不定长数组vector

    #include<iostream> #include<cstdio> #include<vector> #include<algorithm> usi ...