locked
How to call SOAP based web services asynchronously. RRS feed

  • Question

  • User-1042970710 posted

    Hi Folks,

    I have three different webservices method calling one after another.  The first web method provides data to second  and then second web method provide data to the third 

    Here is code my code snippet

     public IActionResult OnPostSubmitImpNotice(int id)
            {
               
                try
                {
    
                    // --> this works fine 
                    SubmitRequestStatus submittedRequest = rayah.SendTanfeedh(ImpNotice.IDNo, ImpNotice.Receiver, ImpNotice.Stage, ImpNotice.NumberOfDays.ToString(), ImpNotice.Sender, ImpNotice.Extension.ToString(), TanfeedhFilePath);
                        ImpNotice.BatchNumber = submittedRequest.BatchNumber;
                        if (submittedRequest.Status=="1")
                        {
                            // -> This method takes a little bit time.
    
                           StatusResponse SentMessageStatus = rayah.GetStatus(submittedRequest.BatchNumber);
                           ImpNotice.BatchIdentifier = SentMessageStatus.BatchIdentifier;
                                   if (SentMessageStatus.Status=="0")
                                   {
                                         / --> this works fine 
                                      DetailedStatus detailedStatus=rayah.GetDetailedStatus(SentMessageStatus.BatchIdentifier);
                                      if(detailedStatus.Status=="0")
                                      {
                                           //....
                                      }
                                   }
                        }
                    return RedirectToPage("/Secure/Operations/Index");
                }
                catch (Exception)
                {
    
                    throw;
                }

    my problem is the second web method  takes a little more time to get the value.... before it can be passed to the third .....

    One way to solve problem is to put a while loop  and keep checking until I get the response but I don't think this is a ideal solution as in that case my screen will freeze until the method completes his job....  my question is how I can transform this service to using Async Call?  

     

    Tuesday, December 22, 2020 12:09 PM

All replies

  • User475983607 posted

    I think you are confusing async with a long running process.  You stated the methods calls in OnPostSubmitNotice are synchronous.  Changing to asynchronous is not going to decrease the time it takes to execute the method. 

    You could run the method in its own task and return from the action which will free the browser.  But you'll need to write code to determine when the process ends.  Typically, you'll store a record in a database table when the process states and update this record when the process stops.  You'll also write client code to check this record as some frequency. 

    Google, long running process in MVC, for code suggestions and samples.

    Tuesday, December 22, 2020 1:18 PM