一个.net项目为web services 。另一个.net项目调用第一个项目 web services.第一个项目:
[WebMethod(EnableSession=true)]
public int getURl()
{
int strid =0;
if (Session["Count"]!=null)
{
strid = (int)Session["Count"] +1;
}
Session["Count"] = strid;
return strid;

第二个项目 中调用webservices 的方法 为:
private void Button1_Click(object sender, System.EventArgs e)
{
System.Net.CookieContainer aab= new System.Net.CookieContainer();
Service1 aa= new Service1();
aa.CookieContainer = aab;
this.TextBox1.Text = aa.getURl().ToString();
}
可我在用第二个项目的方法调用web services 量每次都 得到的是webservices中初使化的  0 值。。 。问高手为什么。?如何解决 。?

解决方案 »

  1.   

    int strid =0;
    if (Session["Count"]!=null)
    {
    strid = (int)Session["Count"] +1;
    }
    Session["Count"] = strid;
    return strid;
    很明显
    if (Session["Count"]!=null)
    {
    strid = (int)Session["Count"] +1;
    }
    没有执行,直接返回了0
    我也在做web service!!
    是一个基于web service的gis系统
      

  2.   

    是的。。后来我用了CooKIE。 也是同样的现象。为NULL
    结果 还是不能 得到预期的值。。请教 高手呀。
      

  3.   

    web service不负责操作你的Session
    你可以把this.Context传进去看看..[WebMethod(EnableSession=true)]
    public int getURl(System.Web.HttpContext context)
    {
    int strid =0;
    if (context.Session["Count"]!=null)
    {
    strid = (int)context.Session["Count"] +1;
    }
    context.Session["Count"] = strid;
    return strid;
    }call:this.TextBox1.Text = aa.getURl().ToString(this.context);