2
我有一个ASMX Web服务的一些网站的方法,目前是这样的:添加自定义属性到ASMX Web服务方法
[WebMethod(false, System.EnterpriseServices.TransactionOption.NotSupported)]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
public XElement GetSomeData(int dataId)
{
// Do something.
}
我希望能够做这样的事情:
[WebMethod(false, System.EnterpriseServices.TransactionOption.NotSupported)]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
[EnableSomeCustomSecurityCheck(true)]
public XElement GetSomeData(int dataId)
{
// Do something.
}
其中“EnableSomeCustomSecurityCheck”告诉它应该有一个额外的令牌参数需要验证。我基本上希望避免将此代码复制到需要它的每种方法:
[WebMethod(false, System.EnterpriseServices.TransactionOption.NotSupported)]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
public XElement GetSomeData(int dataId, string securityToken)
{
SomeClass.CheckSecurityToken(securityToken);
// Do something.
}
我对于从哪里开始有点失落。任何人都可以点我正确的方向,我可以如何添加此功能而不会丢失asmx处理已有的任何功能?
向每种方法添加一行代码与为每种方法添加一行属性之间有什么区别?你试图达到什么样的好处? – pmartin
使用WCF你会更容易。 –
@pmartin:因为我不相信它描述了该方法本身需要如何工作,而是该框架应该如何反应。 – Ocelot20