您好我正在尝试创建异步webmethod。这是创建它的正确方法吗?或者可以指引我正确的文章。
private delegate AuthorizationUpdateResult AuthorizationUpdateDelegate(Authorizations authorization);
/// <summary>
/// The callback.
/// </summary>
/// <param name="asyncResult">The asyncResult.</param>
private AuthorizationUpdateResult AuthorizationCallback(IAsyncResult asyncResult)
{
return new AuthorizationUpdateResult();
//Do Nothing. Maybe Send Response back in future phases
}
[WebMethod]
public void AuthorizationUpdateAsync(Authorizations authorization)
{
AuthorizationUpdateDelegate doAuthorizationUpdateDelegate = new AuthorizationUpdateDelegate(UpdateAuthorization);
AsyncCallback callback = new AsyncCallback(AuthorizationCallback);
doAuthorizationUpdateDelegate.BeginInvoke(authorization, callback, 1239);
}
答案 0 :(得分:0)
就我而言,我使用EventHandlers
调用异步方法:
MyService service = new MyService ();
service.MyServiceCompleted += new MyServiceCompletedEventHandler(this.MyServiceCompleted);
service.MyService Async();
void MyServiceCompleted(object sender, MyServiceCompletedEventArgs args)
{
}