2011-01-07 94 views
3

我想在vb.net中异步调用这个webservice。所以在aspx端我添加了这个属性async =“true”。现在在vb.net代码的一面,我有我的web服务中,我打电话的这个功能。 所以 -在vb.net中异步调用webservice

dim as as webservice.webstring 
as.functionasync(param1, param2) 

现在,当我运行页面,我可以看到,它不会调用WebService的一个timegap之后。 我应该添加.thread.sleep()吗? 我是否需要beginAsyn函数和EndAsyn函数? 我使用asp.net 3.5与IIS7

回答

1

首先,请阅读this MSDN article关于异步页如何在ASP.NET中工作。

其次,您需要在Web服务中使用异步方法。请阅读this HOWTO article,了解如何创建此类方法。

这是你的异步页的执行怎么可能是这样的:

private _as as WebService.WebString = Nothing 

Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load 
    AddOnPreRenderCompleteAsync(New BeginEventHandler(BeginCallingWebService), 
     New EndEventHandler(EndCallingWebService)); 
End Sub 

Private Function BeginCallingWebService(Byval sender As Object, ByVal e As EventArgs, ByVal cb As AsyncCallback, ByVal state As Object) 
    _as = New WebService.WebString() 

    Return _as.BeginMyMethod(cb, state) 
End Function 

Private Sub EndCallingWebService(ByVal ar as IAsyncResult) 
    Dim result As MyWebServiceResult = _as.EndMyMethod(ar) 

    ' Process the result of the web-service method 
End Sub 

希望这会帮助你。