如何使异步服务调用同步调用 [英] How make Async service calls into Sync calls
问题描述
我添加服务作为服务参考。然后是Async部分显示的方法。例如,我创建了userAuthentication方法,但它显示为 userAuthenticationAsync。我怎么需要以同步的方式使用这种方法。
i验证用户为
public bool ValidateUser(string userName,string passWord)
      {
          AuthService.AuthServicesPortTypeClient oAuthClient = new AuthService.AuthServicesPortTypeClient();
          oUserAuth = new AuthService.UserAuth();
          oUserAuth.userName = userName;
          oUserAuth.password = passWord;
          oUserAuth.EMInumber = StaticDetails.getEMINumber();
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; oAuthClient.userAuthenticationCompleted + = new EventHandler< AuthService.userAuthenticationCompletedEventArgs>(oAuthClient_userAuthenticationCompleted);
oAuthClient.userAuthenticationAsync(oUserAuth);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; return retBoolValidateUser;
&NBSP; &NBSP; &NBSP; }
此处 oAuthClient.userAuthenticationAsync(oUserAuth);
方法在完成上述事件调用之前调用。我需要一个接一个地做..
请给我你的建议......
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;
按照以下链接中所述尝试TaskCompletionSource
i added services as service reference. then the methods that displayed with Async part. as a example, i created method as userAuthentication but it display as userAuthenticationAsync. how ever i need to work this method in Sync way.
i Validated user as
public bool ValidateUser(string userName,string passWord)
{
AuthService.AuthServicesPortTypeClient oAuthClient = new AuthService.AuthServicesPortTypeClient();
oUserAuth = new AuthService.UserAuth();
oUserAuth.userName = userName;
oUserAuth.password = passWord;
oUserAuth.EMInumber = StaticDetails.getEMINumber();
oAuthClient.userAuthenticationCompleted += new EventHandler<AuthService.userAuthenticationCompletedEventArgs>(oAuthClient_userAuthenticationCompleted);
oAuthClient.userAuthenticationAsync(oUserAuth);
return retBoolValidateUser;
}
here oAuthClient.userAuthenticationAsync(oUserAuth); method called before finish the above event calling. I need to do one after another..
Please give me your suggestions...
Try TaskCompletionSource as described in following link
这篇关于如何使异步服务调用同步调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!