2012-01-24 47 views
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处理已有的任何功能?

+0

向每种方法添加一行代码与为每种方法添加一行属性之间有什么区别?你试图达到什么样的好处? – pmartin

+0

使用WCF你会更容易。 –

+0

@pmartin:因为我不相信它描述了该方法本身需要如何工作,而是该框架应该如何反应。 – Ocelot20

回答

1

您可以将该属性放在该方法上,然后让Soap Extension检查该属性并相应地执行操作。