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
博客展示了WS端与客户端的异步调用功能。WS端定义了HelloWorld函数,客户端定义了新类Class1,包含beginhellow和Endhellow函数,用于异步调用和获取结果。最后客户端使用这些函数,将结果显示在文本框中,同时处理了可能出现的异常。
334

被折叠的 条评论
为什么被折叠?



