Jam*_*are 4 c# ws-security web-services asmx usernametoken
好的,我们有一个目前在.NET 3.5中运行的传统ASMX Web服务,我们正在使用Visual Studio 2008.
问题是,我们需要添加身份验证,并希望利用WS-Security模型,而不会破坏任何不需要当前身份验证的现有内部客户端.
我们已经考虑过添加自定义标头,但这不是WS-Security-ish.升级到WCF虽然是长期目标,但短期内不可行.
有没有办法间接访问VS2008 ASMX Web服务的soap标头中的UsernameToken(假设它是由客户端传递的)?
您可以尝试Web服务增强(WSE)3.0.这增加了对旧版 WS-Security的支持(我认为2004版本--WCF支持2005和2007版本).它位于ASMX的顶部而不会打扰它,并且仍然可以在.NET 3.5/WS2008中运行.
现在的缺点是:
例
在客户端上指定凭据:
void SetUsernameCredential(WebServicesClientProtocol service, string userName, string password) {
UsernameToken token = new UsernameToken(userName, password, PasswordOption.SendHashed);
service.SetClientCredential(token);
}
Run Code Online (Sandbox Code Playgroud)
验证服务器上的凭据:
public class MyUsernameTokenManager : UsernameTokenManager {
protected override string AuthenticateToken(UsernameToken token) {
// Authenticate here.
// If succeess, return an authenticated IPrincipal and the user's password as shown.
// If failure, throw an exception of your choosing.
token.Principal = principal;
return password;
}
}
Run Code Online (Sandbox Code Playgroud)
读取服务器上的凭据:
IPrincipal principal = RequestSoapContext.Current.IdentityToken.Principal;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11041 次 |
| 最近记录: |