对于ASP.Net Webservice,我希望能够为web.config中的所有webmethods或个别webmethods设置CacheDuration,因此可以在不重新编译解决方案的情况下对其进行调整。从web.config设置WebMethod的CacheDuration?
[WebMethod(CacheDuration=60)]
可以这样做吗?怎么样?
对于ASP.Net Webservice,我希望能够为web.config中的所有webmethods或个别webmethods设置CacheDuration,因此可以在不重新编译解决方案的情况下对其进行调整。从web.config设置WebMethod的CacheDuration?
[WebMethod(CacheDuration=60)]
可以这样做吗?怎么样?
这似乎并不可能。
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
Thx用于格式化代码。 – 2011-05-18 15:10:51
这显示了如何通过在代码中使用属性值来设置缓存持续时间,就像我在我的问题中所做的那样。我想从web.config中完成 – Kjensen 2011-05-18 15:14:01
在AppSettings中保存值可能吗? – eugeneK 2011-05-18 14:56:23
问题不在于节省价值,问题在于将值应用于web方法。 – Kjensen 2011-05-18 15:01:09