Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 会话变量在不同的Web服务方法中返回空值_C#_Web Services_Session - Fatal编程技术网

C# 会话变量在不同的Web服务方法中返回空值

C# 会话变量在不同的Web服务方法中返回空值,c#,web-services,session,C#,Web Services,Session,我必须使用webmethod,我想在其中使用会话变量 [WebMethod(enableSession: true)] public List<int> FirstMethod() { List<int> ListValue=getListValue(); Session["ListValue"]=ListValue; return ListValue; //It works fine and it also return List of integer

我必须使用webmethod,我想在其中使用会话变量

 [WebMethod(enableSession: true)]
        public List<int> FirstMethod()
{
List<int> ListValue=getListValue();
Session["ListValue"]=ListValue;
return ListValue;
//It works fine and it also return List of integers which is ok 
}
        [WebMethod(enableSession: true)]
                    public List<int> SecondMethod()
            {
        if(Session["ListValue"]!=null)//null value in session :(
        {List<int> ListValue=(List<int>)Session["ListValue"];
        return ListValue;
    }
    else 
    return null;
        }
}
现在我想在另一个不起作用的方法中使用ListValue的这个会话值,它会返回null值,而不是像这样的List

 [WebMethod(enableSession: true)]
        public List<int> FirstMethod()
{
List<int> ListValue=getListValue();
Session["ListValue"]=ListValue;
return ListValue;
//It works fine and it also return List of integers which is ok 
}
        [WebMethod(enableSession: true)]
                    public List<int> SecondMethod()
            {
        if(Session["ListValue"]!=null)//null value in session :(
        {List<int> ListValue=(List<int>)Session["ListValue"];
        return ListValue;
    }
    else 
    return null;
        }
}

请注意:尝试创建无状态服务,而不是有状态服务。顺序词:根本不要使用会话。你可以看一看希望它有帮助。我在这方面是新的,请解释我不能理解建议的urlanswer@L-三请详细说明无状态和有状态之间的区别。另见