WCF自定义用户名密码验证器程序集加载失败问题求助
解决WCF自定义CustomUserNameValidator加载失败问题
核对完全限定名与程序集名称
customUserNamePasswordValidatorType必须严格遵循「命名空间.类名, 程序集名称」格式,比如验证器类在MyWcfService.Security命名空间,程序集叫MyWcfService,配置要写成:<customUserNamePasswordValidator type="MyWcfService.Security.CustomUserNameValidator, MyWcfService" />注意别加
.dll后缀,大小写也要和实际一致。确认类的编译与部署状态
- 检查CustomUserNameValidator类是否成功编译到项目输出的.dll文件里
- 部署服务时,确保该程序集已经复制到服务的bin目录,没有遗漏任何依赖文件
检查类的访问权限
CustomUserNameValidator必须是public修饰的,并且正确继承System.IdentityModel.Selectors.UserNamePasswordValidator,如果是internal类,WCF根本加载不了。验证配置节点层级
确保<customUserNamePasswordValidator>节点嵌套在<serviceCredentials>→<userNameAuthentication>下,正确结构如下:<serviceCredentials> <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="你的完全限定名, 程序集名" /> </serviceCredentials>节点层级错了,WCF会忽略配置,导致加载失败。
排查依赖项缺失
要是提示依赖项加载失败,用Visual Studio编译时的「输出」窗口查看细节,或者用fuslogvw.exe(程序集绑定日志查看器)定位缺失的依赖,把对应的程序集放到bin目录里。
内容的提问来源于stack exchange,提问作者Dragon
相关产品推荐
相关产品推荐

