All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
关于webservice的异步调用实例_[Asp.Net教程]

Writer: delv Article type: Programming skills(编程技巧) Time: 2014/1/6 9:09:43 Browse times: 281 Comment times: 0

关于webservice的异步调用实例_[Asp.Net教程]


Head photo

Go homepage
Upload pictures
Write articles

关于webservice的异步调用实例_[Asp.Net教程]

关于webservice的异步调用简单实例
无论在任何情况下,被调用方的代码无论是被异步调用还是同步调用的情况下,被调用方的代码都是一样的,

下面,我们就以异步调用一个webservice 为例作说明。
这是一个webservice

_
Public Function delCurTable(ByVal tbName As String) As Boolean
Try
Return True
Catch ex As Exception
Return False
End Try
End Function

关于这个webservice的同步调用方法,我就不做说明了
异步调用:
Private a As vbwebservice.DataManage'定义一个webservice变量
Dim ar As IAsyncResult
public sub Callback1(byval ar as IAsyncResult)
''这里可以不写任何代码
'这里的代码在调用方运行结束后,开始运行
end sub

#region "异步调用"
private sub btnStart_Click()
dim cb as asyncallback=new asyncallback(address(me.callback1))
ar=a.begindelcurtable("zdf",cb,a)
end sub


private sub btnEnd_Click()
if ar is nothing then
exit sub
end if
if ar.IsCompleted Then
dim m as boolean=a.enddelcurtable(ar)
messagebox.show(m.tostring)
end if
end sub
#end region
注意:“返回异步调用的结果一次只能调用一次,如果想再执行一遍,就必须重新执行一遍begin的方法”
以上是vb.net的用法,下面是c#的用法
CWebService.DataManage a;
System.IAsyncResult ar;
private void Form1_Load(object sender, System.EventArgs e)
{
a=new CWebService.DataManage();
}


public void CallBack1(System.IAsyncResult ar)
{
}

private void btnStart_Click(object sender, System.EventArgs e)
{
System.AsyncCallback cb=new AsyncCallback(this.CallBack1);
ar=a.BegindelCurTable("zhang",cb,a);
}

private void btnEnd_Click(object sender, System.EventArgs e)
{
if(ar==null)
{
MessageBox.Show("null");
return ;
}
if(ar.IsCompleted )
{
bool m=a.EnddelCurTable(ar);
MessageBox.Show(m.ToString());
}
else
{
MessageBox.Show("为完成");
}
}

来源:网络





There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.