在会话c#中保存数组错误

在会话c#中保存数组错误,c#,asp.net,web-services,C#,Asp.net,Web Services,我正在尝试在会话中保存数组并尝试将其取回。 下面是代码。但是当我调用WebMethod时,我得到了以下错误。我用的是c#。VS2010 错误: System.NullReferenceException:对象引用未设置为实例 指一个物体。在中的xmlRW1.Service1.logic()处 C:\Users\uydarp\Documents\Visual Studio 2010\Projects\xmlRW1\xmlRW1\Service1.asmx.cs:第86行 默认情况下,asmx服务中

我正在尝试在会话中保存数组并尝试将其取回。 下面是代码。但是当我调用WebMethod时,我得到了以下错误。我用的是c#。VS2010

错误:

System.NullReferenceException:对象引用未设置为实例 指一个物体。在中的xmlRW1.Service1.logic()处 C:\Users\uydarp\Documents\Visual Studio 2010\Projects\xmlRW1\xmlRW1\Service1.asmx.cs:第86行


默认情况下,
asmx
服务中禁用会话状态。您可以通过更改
WebMethod
属性来显式启用它:

[WebMethod(EnableSession = true)]
public int logic()
{
    int[] myArray = { 1,2,3,4};
    Session["MyArray"] = myArray; 

    int[] myArray2 = (int[])Session["MyArray"];
    int firstElement = myArray2[0];

    return firstElement;
}

默认情况下,
asmx
服务中禁用会话状态。您可以通过更改
WebMethod
属性来显式启用它:

[WebMethod(EnableSession = true)]
public int logic()
{
    int[] myArray = { 1,2,3,4};
    Session["MyArray"] = myArray; 

    int[] myArray2 = (int[])Session["MyArray"];
    int firstElement = myArray2[0];

    return firstElement;
}

web.config中的会话超时值是多少?我在web.config文件中找不到任何超时。我只有web.config文件中的和。使用[WebMethod(EnableSession=true)]web.config中的会话超时值是多少?我在web.config文件中找不到任何超时。我只有web.config文件中的和。使用[WebMethod(EnableSession=true)]