WebService属性和方法

29 篇文章 0 订阅
4 篇文章 0 订阅

如果需要在ClientServer端保持状态信息,则可以使用EnableSession属性。缺省情况下EnableSessionfalse  

  WebService端代码:   

Public Property Connect() As String

    <WebMethod(EnableSession:=True)> Get

        Return Session("_str")

    End Get

    <WebMethod(EnableSession:=True)> Set(ByVal Value As String)

        Session("_str") = Value

    End Set

End Property

 

Public Property SQL() As String

    <WebMethod(EnableSession:=True)> Get

        Return Session("_str1")

    End Get

    <WebMethod(EnableSession:=True)> Set(ByVal Value As String)

        Session("_str1") = Value

    End Set

End Property

  然后在VB.NETApplicaton中可以安装如下方式调用上述Web Service  

  如下只是一个简单的测试代码,可供参考:

Button2_Click方法中可以第二次获取Session("_str")的值,不需要重新再赋值。  

  Imports   System.Net  

Dim ws As localhost.HelloWorld = New localhost.HelloWorld()

  ……  

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    ws.CookieContainer = New CookieContainer()

End Sub

 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim strTemp As String

    ws.set_Connect("Connected!")

    strTemp = ws.get_Connect()

    TextBox1.Text = TextBox1.Text & strTemp

    ws.set_SQL("SQL")

    strTemp = ws.get_SQL()

    TextBox1.Text = TextBox1.Text & Chr(13) & Chr(10) & strTemp

End Sub

 

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

    TextBox1.Text = TextBox1.Text & ws.get_Connect()

End Sub

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值