您的位置:首页 > 其它

终于会使用异步调用ws了,高兴啊

2004-10-25 17:17 309 查看
ws端
<WebMethod(Description:="异步调用演示")> _
Public Function HelloWorld(ByVal temp As String) As String
Return temp
End Function

客户端定义的新类

Public Class Class1
Private m_WsData As New localhost.Service1

Public Function beginhellow() As IAsyncResult
Try
Return m_WsData.BeginHelloWorld("下午好", Nothing, New Object)
Catch ex As Exception
MessageBox.Show("beginhellow发生错误!" & ex.Message & vbNewLine & ex.StackTrace)
Return Nothing
End Try
End Function

Public Function Endhellow(ByVal ar As IAsyncResult) As String
Dim temp As String
Try
Return m_WsData.EndHelloWorld(ar)
Catch ex As Exception
Return "Endhellow发生错误!" & ex.Message & ex.StackTrace
End Try
End Function
End Class

客户端使用

Dim temp As New Class1
Dim ar As IAsyncResult
ar = temp.beginhellow()
'ar.AsyncWaitHandle.WaitOne()

If (ar.IsCompleted) Then
Dim result As String
result = temp.Endhellow(ar)
TextBox1.Text = result
End If
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: