我在 asmx 网络服务中有一些网络方法,目前看起来像这样:
[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”告诉它应该有一个额外的 token 参数需要验证。我基本上想避免将此代码复制到每个需要它的方法:
[WebMethod(false, System.EnterpriseServices.TransactionOption.NotSupported)]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
public XElement GetSomeData(int dataId, string securityToken)
{
SomeClass.CheckSecurityToken(securityToken);
// Do something.
}
我有点不知道从哪里开始。谁能指出我如何在不丢失 asmx 处理已有的任何功能的情况下添加此功能的正确方向?
最佳答案
你可以把属性放在方法上,然后有一个Soap Extension检查属性并相应地进行操作。
关于c# - 将自定义属性添加到 ASMX Web 服务方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8992208/