Enable Session Cache Duration and Buffered Response in webservice page

Today i want to discuss an article how to Maintain a Session state in your webservice ,CachingDuration ,Buffer Response, Description of Web Method in a webservice.This is the article i want to discuss here with code snippets and real time images

All of us know how to use session,caching and Buffered output time in aspx page.But many programmers do not know how to use it in asmx page i.e in webservice page.So for that how to use Enablesession attribute,Buffer Response and CacheDuration in asmx page i will discuss here in this article with output images.

Some scenarios we need to carry session data in our .asmx page(i.e in webservice page) for that asmx page have an session class but it will not be enabled by default in that page so how to enable session data,cacheduration and Buffer Response in asmx page.

Here is the schema for You.

[WebMethod(EnableSession=true, BufferResponse = true,CacheDuration=60, Description = "Submit Quick SMS. oMesgType (0-English,8-Arabic), MsgDestinations: Comma delimited mobiles, DLREnable: (0 - Disable, 1 - Enable)")]
public string SubmitMessage(string UserName, string Password, string Message, string oMesgType, string SenderID, string MsgDestinations, string DLREnable)
string strTransactionID = "";
string strMBC = string.Empty;
WriteToFile(m_strUpLoadPath, "Preparing the xml.", true);
if (!SetSMSDetails(UserName, Password, strMBC, SenderID, oMesgType, MsgDestinations, Message, DLREnable.Trim(), ref strTransactionID))
WriteToFile(m_strUpLoadPath, "Failed to prepare the xml." + m_strLastError, true);
return m_strLastError;
catch (Exception ex)
WriteToFile(m_strUpLoadPath, "Exception: SubmitMessage\t" + ex.Message, true);
return ex.Message;
return strTransactionID;

Image of asmx page in real time ...

Webservice Attribute

Enable Session =true : Indicates Enable session state is Enabled for xml service method

Buffer Response=true : Gets or sets whether the response for this request is buffered.

CacheDuration=60(in Seconds) : Gets or sets the number of seconds that should be held in cache.

Description : A Descriptive message describing the xml web service method.

You need to declare all these attributes at the top of the webservice method as in the square brackets

Hope this Article will be Useful for Your Purpose.


Article by srirama
A Good advice from parent to a Child , Master to a Student , Scholar to an Ignorant is like a doctor prescribed pill it is bitter to take but when they take it will do all good for them --- Bhushan

Follow srirama or read 74 articles authored by srirama


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: