好的,我们有一个遗留的ASMX web服务,它目前运行在.NET 3.5中,我们使用的是Visual Studio2008。
问题是,我们需要添加身份验证,并且希望在不破坏当前不需要身份验证的任何现有内部客户端的情况下利用WS-Security模型。
我们考虑过添加自定义头,但这并不是很符合WS-Security的要求。此外,升级到WCF,虽然是一个长期目标,但在短期内是不可行的。
有没有办法在VS2008 ASMX web服务的soap头中间接访问UsernameToken (假设它是由客户端传递的)?
发布于 2009-12-09 00:59:24
你可以试试Web Services Enhancements (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);
}正在服务器上验证凭据:
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;
}
}正在读取服务器上的凭据:
IPrincipal principal = RequestSoapContext.Current.IdentityToken.Principal;https://stackoverflow.com/questions/1868246
复制相似问题