紧急,应用程序调用webservice时出的问题

mao642 2003-08-21 11:13:37
我的webservice如下:

public string ID="";

....

[WebMethod(EnableSession=true)]
public string GetID()
{
return this.ID;
}
[WebMethod(EnableSession=true)]
public void SetID(string str)
{
this.ID = str;
}

...

用asp.net调用它的时候,
myService.SetID("hehe")
则myService.GetId() == "hehe

而在用c#写的应用程序客户端如此调用
myService.SetID("hehe");
string str myService.GetId();

则str==null

请教达人,不知什么原因啊~~~
...全文
29 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
minajo21 2003-08-21
  • 打赏
  • 举报
回复
呵呵,老大来了
saucer 2003-08-21
  • 打赏
  • 举报
回复
you might need to replace Session with System.Web.HttpContext.Current.Session if your class is not derived from WebService class
saucer 2003-08-21
  • 打赏
  • 举报
回复
everytime you call a webmethod, a new instance of the webservice class is created, try the following


//public string ID="";

public string ID
{
get
{
if (Session["ID"] == null)
return "";
return (string)Session["ID"];
}
set
{
Session["ID"] = value;
}
}

[WebMethod(EnableSession=true)]
public string GetID()
{
return this.ID;
}
[WebMethod(EnableSession=true)]
public void SetID(string str)
{
this.ID = str;
}


don't forget to create a CookieContainer for your client side proxy object:

myService.CookieContainer = new CookieContainer();
myService.SetID("hehe");
string str = myService.GetId();
panyee 2003-08-21
  • 打赏
  • 举报
回复
用Session["ID"].ToString(),
minajo21 2003-08-21
  • 打赏
  • 举报
回复
注意,每次连接要重新构造一次
minajo21 2003-08-21
  • 打赏
  • 举报
回复
注意,每次连接要重新构造一次
panyee 2003-08-21
  • 打赏
  • 举报
回复
ID是什么?

return Session["ID"].ToString(); 试试
panyee 2003-08-21
  • 打赏
  • 举报
回复
ID是什么?

return Session["ID"].ToString(); 试试
panyee 2003-08-21
  • 打赏
  • 举报
回复
ID是什么?

return Session["ID"].ToString(); 试试
mao642 2003-08-21
  • 打赏
  • 举报
回复
谢谢大家了

12,162

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 Web Services
社区管理员
  • Web Services社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧