【问题标题】:Setting CacheDuration on a WebMethod from web.config?从 web.config 在 WebMethod 上设置 CacheDuration?
【发布时间】:2011-05-18 14:50:49
【问题描述】:

对于 ASP.Net Webservice,我希望能够在 web.config 中为所有 webmethods 或单个 webmethods 设置 CacheDuration,以便无需重新编译解决方案即可对其进行调整。

[WebMethod(CacheDuration=60)]

可以吗?怎么样?

【问题讨论】:

  • 可能在 AppSettings 中保存价值?
  • 问题不在于保存值,问题在于将值应用到 webmethod。

标签: asp.net web-services asp.net-4.0


【解决方案1】:

这似乎是不可能的。

【讨论】:

    【解决方案2】:

    VB

    Public Class Service1
        Inherits System.Web.Services.WebService
        <System.Web.Services.WebMethod(CacheDuration:=60)> _
        Public Function ConvertTemperature(ByVal dFahrenheit As Double) _
                                           As Double
            ConvertTemperature = ((dFahrenheit - 32) * 5) / 9
        End Function
    End Class
    

    C#

    public class Service1 : System.Web.Services.WebService
    { 
        [System.Web.Services.WebMethod(CacheDuration=60)]
        public double ConvertTemperature(double dFahrenheit)
        {
           return ((dFahrenheit - 32) * 5) / 9;
        }
    }
    

    来源:http://msdn.microsoft.com/en-us/library/byxd99hx%28v=vs.80%29.aspx

    【讨论】:

    • 这显示了如何通过在代码中使用属性值来设置缓存持续时间,正如我在我的问题中所做的那样。我想通过 web.config 来做
    猜你喜欢
    • 1970-01-01
    • 2012-06-04
    • 1970-01-01
    • 2011-03-09
    • 1970-01-01
    • 2011-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多