終於會使用異步調用ws了,高興啊

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章