0

I am trying to save value in session in webservice but it gives me error: object reference not set to an instance of an object.

Session["ProcessStartTime"] = strDate;
algreat
  • 8,592
  • 5
  • 41
  • 54

2 Answers2

0

Add (EnableSession = True) to the WebMethod

[WebMethod (EnableSession = true)]

or Read this nice article on How to use session state in web service

ZedBee
  • 2,320
  • 7
  • 39
  • 61
0
  1. Make sure your strDate not null
  2. check you enabled session using Session["ProcessStartTime"] = strDate; before declaration method

here is a sample

public class mytest: System.Web.Services.WebService
    {
        [WebMethod (EnableSession = true)]
        public string HelloWorld()
        {
           //your logic here
            if(strDate!=null)
                  Session["ProcessStartTime"] = strDate;
            else
                 // handle if ur strDate is null
         }
    }
Anant Dabhi
  • 10,864
  • 3
  • 31
  • 49