I have some web methods in an asmx web service that currently look like this:
[WebMethod(false, System.EnterpriseServices.TransactionOption.NotSupported)]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
public XElement GetSomeData(int dataId)
{
// Do something.
}
I want to be able to do something like this:
[WebMethod(false, System.EnterpriseServices.TransactionOption.NotSupported)]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
[EnableSomeCustomSecurityCheck(true)]
public XElement GetSomeData(int dataId)
{
// Do something.
}
Where “EnableSomeCustomSecurityCheck” tells it that there should be an additional token parameter that needs to be validated. I basically want to avoid copying this code to every method that needs it:
[WebMethod(false, System.EnterpriseServices.TransactionOption.NotSupported)]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
public XElement GetSomeData(int dataId, string securityToken)
{
SomeClass.CheckSecurityToken(securityToken);
// Do something.
}
I’m a bit lost as to where to begin. Can anyone point me in the right direction for how I can add this functionality without losing any features the asmx handling already has?
You can place the attribute on the method, and then have a Soap Extension check the attribute and behave accordingly.