我正在使用传统的.net 2.0 .asmx Web服务(试图说服他们切换到WCF,但没有运气)。我试图找到一种方法,不仅可以使用自定义SOAP头,还可以在每个链接中没有验证码的情况下对用户进行验证。尝试重写SoapHeaderAttribute以将身份验证添加到属性
目前,我的web服务看起来是这样的:
public WebserviceAuthentication currentUser;
[WebMethod(Description="Returns the logged in users credentials")]
[SoapHeader("currentUser")]
public string HelloWorld()
{
var user = AuthenticateUser(currentUser, WebServiceResources.MEDICAREELIGIBILITY_HELLOWORLD);
return string.Format("{0} {1} {2}", user.User.UserName, user.User.ProviderUserKey, user.AccountId);
}
理想情况下,我的代码更改为以下:
public WebserviceAuthentication currentUser;
public CustomAuthentication user;
[WebMethod(Description="Returns the logged in users credentials")]
[SoapHeaderAuthentication("currentUser")]
public string HelloWorld()
{
return string.Format("{0} {1} {2}", user.User.UserName, user.User.ProviderUserKey, user.AccountId);
}
SoapHeaderAuthentication会读取currentUser和确认信息注册用户。如果是,则返回自定义用户对象并填充用户对象。然后我可以从WebService中访问用户对象。
问题是,我无法扩展SoapHeaderAttribute,因为它是一个密封的类。
可以使用WSE吗? – 2012-01-03 20:32:22
可能。你有一个例子吗? – Cyfer13 2012-01-03 20:42:43
不是。我只是知道,在最近的实施中,我能够更好地控制WSE的头部。 – 2012-01-04 01:23:46