向 ASMX Web 服务方法添加自定义属性
我在 asmx Web 服务中有一些 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 处理已有的任何功能?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将该属性放在方法上,然后使用 Soap Extension 检查属性并做出相应的行为。
You can place the attribute on the method, and then have a Soap Extension check the attribute and behave accordingly.