为什么我不能将我的Object传递给在Web Service中创建的会话

时间:2012-01-30 07:16:25

标签: c# asp.net web-services

为什么我不能将我的Object传递给在Webservice中创建的会话?

[WebMethod]
public void UpdatedData(string CountryName, string CountryCode,
                        string City, string RegionCode, string RegionName) 
{            
    Chat ch = new Chat();
    ch.CountryName = CountryName;
    ch.CountryCode = CountryCode;
    ch.City = City;
    ch.RegionCode = RegionCode;
    ch.RegionName = RegionName;
    Session["Chat"] = ch;  //object Refrence not set to instance of an object
}

2 个答案:

答案 0 :(得分:3)

请在上面的方法上面加上以下代码:

[System.Web.Services.WebMethod(EnableSession=true)]

答案 1 :(得分:1)

 [ WebMethod(Description="Per session Hit Counter",EnableSession=true)]
public void UpdatedData(string CountryName, string CountryCode, string City, string RegionCode, string RegionName) 
{
Chat ch = new Chat(); 
ch.CountryName = CountryName; 
ch.CountryCode = CountryCode; 
ch.City = City; ch.RegionCode = RegionCode; 
ch.RegionName = RegionName; 
Session["Chat"] = ch;
}