向 ASMX Web 服务方法添加自定义属性

发布于 2024-12-28 20:37:04 字数 979 浏览 2 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沙沙粒小 2025-01-04 20:37:04

您可以将该属性放在方法上,然后使用 Soap Extension 检查属性并做出相应的行为。

You can place the attribute on the method, and then have a Soap Extension check the attribute and behave accordingly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文