REST WCF 中的身份验证问题
我已经开发了 REST WCF 并在 web.config 中设置了以下方式的绑定
<bindings>
<webHttpBinding>
<binding name="secureBasic">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="None" />
</security>
</binding>
</webHttpBinding>
</bindings>
<serviceBehaviors>
<behavior name="ServiceBehaviour" >
<serviceCredentials>
<userNameAuthentication customUserNamePasswordValidatorType="RestService.CustomUsernamePasswordValidator, RestService"
userNamePasswordValidationMode="Custom" />
</serviceCredentials>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
在 CustomUsernamePasswordValidator.cs 文件中,我通过以下方式对用户进行了身份验证
namespace RestService
{
public class CustomUsernamePasswordValidator : UserNamePasswordValidator
{
public override void Validate(string userName, string password)
{
if (!AuthenticateUser(userName, password))
throw new SecurityTokenValidationException("Invalid Username or Password");
}
private bool AuthenticateUser(string userName, string password)
{
if (userName == "myaddon" && password == "mypassword")
{
return true;
}
else
return false;
}
}
}
现在的问题是,当我从同一个项目使用此服务时,它运行良好,但对为什么要进行此调用感到困惑验证不会发生?
另外,当我从 ruby commnad propmpt 测试我的heroku清单插件文件时,它给了我错误 认证失败!!我认为这是我的 REST WCF 应用程序的问题。
如果有人非常了解 WCF 和身份验证,请任何人都可以帮助我解决这个问题。
谢谢 阿伦.
I have developed REST WCF and set binding following way in web.config
<bindings>
<webHttpBinding>
<binding name="secureBasic">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="None" />
</security>
</binding>
</webHttpBinding>
</bindings>
<serviceBehaviors>
<behavior name="ServiceBehaviour" >
<serviceCredentials>
<userNameAuthentication customUserNamePasswordValidatorType="RestService.CustomUsernamePasswordValidator, RestService"
userNamePasswordValidationMode="Custom" />
</serviceCredentials>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
And in CustomUsernamePasswordValidator.cs file i have authenticate user by following way
namespace RestService
{
public class CustomUsernamePasswordValidator : UserNamePasswordValidator
{
public override void Validate(string userName, string password)
{
if (!AuthenticateUser(userName, password))
throw new SecurityTokenValidationException("Invalid Username or Password");
}
private bool AuthenticateUser(string userName, string password)
{
if (userName == "myaddon" && password == "mypassword")
{
return true;
}
else
return false;
}
}
}
Now problem is that it is running nice when i will use this service from same project but confused that why this call would not occurred for validation?
Also when i test my heroku manifest addon file from ruby commnad propmpt it give me error of
Failed Authentication !! I think this is issue of my REST WCF Application.
Please anyone can help me to solve this issue if anyone know very well about WCF and authentication.
Thanks
Arun.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最后,我直接使用 WebOperationContext 处理自定义身份验证并跳过 Web.Config 设置。
Finally i have handle custom authentication using WebOperationContext directly and skip the Web.Config settings.