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