I’m stucking use a legacy .net 2.0 .asmx web services (tried to convince them to switch to WCF but no luck there). I’m trying to find a way to not only use a custom SOAP header, but also to authenticate the user without having the authentication code in each link.
Currently, my web service looks like this:
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);
}
Ideally, I’d change the code to the following:
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 would read the currentUser and confirm that the information is a registered user. if they are, return the custom user object and populate the user object. I could then access the user object from within the WebService.
The problem is, I can’t extend the SoapHeaderAttribute because it’s a sealed class.
This is going back a bit, but I wrote an article that you could extend: here