CSDN博客

img kevin521

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

发表于2004/10/25 17:17:00  1122人阅读

分类: vb.net

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

阅读全文
0 0

相关文章推荐

img
取 消
img