You must Sign In to post a response.
  • Category: Webservices

    Session i n webservice


    how to use session in webservice? and what all r the uses For that i Mentioned below Coding

  • #455494
    try this

  • #456793
    using System.Web.Services;

    public class Util: WebService {
    [ WebMethod(Description="Per session Hit Counter",EnableSession=true)]
    public int SessionHitCounter() {
    if (Session["HitCounter"] == null) {
    Session["HitCounter"] = 1;
    else {
    Session["HitCounter"] = ((int) Session["HitCounter"]) + 1;
    return ((int) Session["HitCounter"]);

    Rakesh Sharma, NEPL

  • #457598
    Enabling Session Support on the Server
    By default, ASP.NET session support for each Web method is turned off. You must explicitly enable session support for each Web method that wants to use session state. This is done by adding the EnableSession property to the WebMethod attribute of your function. The code for a Web method with the EnableSession property set to true, and which accesses the HttpSessionState object, is shown below.

    Copy Code
    <WebMethod(EnableSession:=True)> _
    Public Function IncrementSessionCounterX() As Integer
    Dim counter As Integer
    If Context.Session("Counter") Is Nothing Then
    counter = 1
    counter = Context.Session("Counter") + 1
    End If
    Context.Session("Counter") = counter
    Return counter
    End Function

    As you might expect, if you enable session support for one Web method, that does not imply that it is enabled for another Web method. In fact, the Context.Session property will be null if EnableSession is not explicitly set to True for a particular Web method.

    Regards & thanks
    Arvind kumar

  • #460321
    check here,

  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.