当前位置:编程学习 > C#/ASP.NET >>

怎么在webservice中添加cache?

html:
<atlas:ScriptManager runat="server" ID="scriptManager">
    <Services>
        <atlas:ServiceReference Path="CachedWebService.asmx" />
    </Services>
</atlas:ScriptManager>


js代码:
function btnInvoke_onclick() {
    CachedWebService.GetGurrentTime(onCompleted);
}
function onCompleted(result) {
    $('result').innerHTML += result + "<br />";
}


C#中webservice代码:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class CachedWebService : System.Web.Services.WebService
{
    [WebMethod]
    public DateTime GetGurrentTime()
    {
        return DateTime.Now;
    }
}


要启用Web Service的Cache --------------------编程问答-------------------- 传送门 --------------------编程问答-------------------- http://support.microsoft.com/kb/318299
  
*****************************************************************************
签名档: http://feiyun0112.cnblogs.com/ --------------------编程问答-------------------- --------------------编程问答-------------------- 什么是“Web Service的Cache ”呢? --------------------编程问答-------------------- 只需要在WebMethod的声明中添加如下属性:
[WebMethod(CacheDuration = 5)]

其中CacheDuration的值代表Cache的时间,单位为秒。
但这种Cache的方法是Web Service提供的,每次调用还是被发送给服务器。所以对于网络上延迟对用户的影响,这种Cache没有办法改善。
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,