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