在Asp.Net 2.0里,已经能够在WebMethod里使用 Session 、 Application 这种服务器变量了。

一、Session
Webservice中使用Session、Application    [WebMethod(EnableSession = true)]
Webservice中使用Session、Application    
public string Hello() 
    }

“EnableSession” 为 XML Web services 方法启用会话状态,启用为 true。默认状态为 false。

以上三种方式均能实现对Session变量的使用。但要注意:

如果状态设置为 true,则客户端访问WS时,可以不赋值Session变量,有默认值。
如果状态设置为 false,则客户端访问WS时,必须要先对Session变量赋值,否则报错。

二、Application
Webservice中使用Session、Application    [WebMethod]
Webservice中使用Session、Application    
public string Hello3()
    }

使用Application时,不需要设置方法标签

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-05
  • 2022-02-08
  • 2021-11-16
  • 2021-12-18
  • 2022-12-23
猜你喜欢
  • 2021-09-07
  • 2021-12-30
  • 2022-12-23
  • 2021-06-23
  • 2022-12-23
相关资源
相似解决方案