XAM150 - SOAP and REST (Class with René, 2014-09-25)

rene_ruppertrene_ruppert DEXamarin Team, University, XamUProfessors Xamurai

Thanks for attending today's class!
Even though I got lost a bit with too many braces, we managed to fix everything in the end. :-)

There was a very good question: why don't we use the async versions of the methods in the SOAP client?
We can, but we probably want to convert them over to async/await and that's what we did. Here's the code:

To make the SOAP method be truly async, use something like this (notice that you still will have to take care of the multiple event subscriptions - maybe use a static event handler and remove it before adding it back in):

public Task<List<Model.DrugInfo>> GetDataAsync()
  var tcs = new TaskCompletionSource<IEnumerable<Core.Model.DrugInfo>> ();

  using (var soapClient = new DBManagerService ())

    // Note: this line is an issue. It keeps on adding callbacks over time!
    soapClient.getDrugsCompleted += async (object sender, getDrugsCompletedEventArgs args) => {
      var convertedData = await MapSoapDtoToConceptPropertyAsync (args.Result);
    soapClient.getDrugsAsync ("aspirin");
  return tcs.Task;
Sign In or Register to comment.