Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Caching and State Management within WebServices

Caching and State Management within WebServices

Scheduled Pinned Locked Moved Web Development
questioncsharpasp-netdatabasedesign
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RadioButton
    wrote on last edited by
    #1

    Hello, I was wondering 'if this is even possible' what is the "right" way to perform caching and state management within WebServices with ASP.Net 2.0? Or should you just use System.IO.MemoryStream? :doh: My Scenario is: UI will hit WebService lets say every 10 min and request data. However I don't want every user hitting the WebService to make a call to SQL. Just need to be pointed in the right direction. Thank you for the help. RB

    D 1 Reply Last reply
    0
    • R RadioButton

      Hello, I was wondering 'if this is even possible' what is the "right" way to perform caching and state management within WebServices with ASP.Net 2.0? Or should you just use System.IO.MemoryStream? :doh: My Scenario is: UI will hit WebService lets say every 10 min and request data. However I don't want every user hitting the WebService to make a call to SQL. Just need to be pointed in the right direction. Thank you for the help. RB

      D Offline
      D Offline
      Dominic Pettifer
      wrote on last edited by
      #2

      While State Management IS supported, it's generally not a recommended practice to implement it with web services due to scalability and practical reasons. Also you need to make sure that whatever is calling it also supports state management, typically via HTTP Cookies. You implement it like this... [WebMethod(EnableSession=true)] public Object DoSomething(){} Then, providing you're deriving from System.Web.Services.WebService, you use Session same way you use it in ASP.NET web pages. However, if the caller doesn't support stateful webservice, then the Session values will be emptied with every call. If the caller is also a .NET app then enabling stateful Web Service support is entirely possible, write back and I'll post some code. As for Caching, yes this is possible and recommended. You could do this manually using the Cache property of System.Web.Services.WebService (same way as ASP.NET web pages), or get the WebService to handle Caching itself like this... [WebMethod(CacheDuration=600)] public Object DoSomething(){} This will cache the output of the web service for 10 minutes (600 seconds). It's also intelligent enough to detect input parameters in the WebMethod and Cache different outputs depending on the input params. Although if lots a input params are used, you could end up caching lots of data and flooding the servers memory, so be careful.

      Dominic Pettifer Blog: www.dominicpettifer.co.uk

      R 1 Reply Last reply
      0
      • D Dominic Pettifer

        While State Management IS supported, it's generally not a recommended practice to implement it with web services due to scalability and practical reasons. Also you need to make sure that whatever is calling it also supports state management, typically via HTTP Cookies. You implement it like this... [WebMethod(EnableSession=true)] public Object DoSomething(){} Then, providing you're deriving from System.Web.Services.WebService, you use Session same way you use it in ASP.NET web pages. However, if the caller doesn't support stateful webservice, then the Session values will be emptied with every call. If the caller is also a .NET app then enabling stateful Web Service support is entirely possible, write back and I'll post some code. As for Caching, yes this is possible and recommended. You could do this manually using the Cache property of System.Web.Services.WebService (same way as ASP.NET web pages), or get the WebService to handle Caching itself like this... [WebMethod(CacheDuration=600)] public Object DoSomething(){} This will cache the output of the web service for 10 minutes (600 seconds). It's also intelligent enough to detect input parameters in the WebMethod and Cache different outputs depending on the input params. Although if lots a input params are used, you could end up caching lots of data and flooding the servers memory, so be careful.

        Dominic Pettifer Blog: www.dominicpettifer.co.uk

        R Offline
        R Offline
        RadioButton
        wrote on last edited by
        #3

        Thank you very much for the information. Very helpful. :-D

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups