title: how do i call webservice from MVC3 Razor Controller?
body: <p>In my project I need to call a web service from a controller. I have already done the following, and it works.</p>
  
  <ol>
  <li><p>Add the web reference for the web service to the project.</p></li>
  <li><p>Call the service as follows:</p>
  
  <pre><code>Service Wservice=new Service();
  Wservice.loginCompleted+=new Wservice_login_Completed;
  WService.login_Async("username","Password");
  </code></pre>
  
  <p>Note: Whenever i call this service it throws an error that is 
  "An asynchronous operation cannot be started at this time.
  Asynchronous operations may only be started within an asynchronous handler 
  or module or during certain events in the Page lifecycle. If this
  exception occurred while executing a Page, ensure that the Page is marked 
  &lt;%@ Page Async="true" %>."</p></li>
  </ol>
  
  <p>To overcome this issue I use </p>
  
  <pre><code> [Httppost]
   public ActionResult login(logmodel model)
   {
     Task.Factory.StartNew(() =&gt; 
      { 
      Wservice.loginCompleted+=new Wservice_login_Completed;
      WService.login_Async("username","Password");
      });
  
      if(finalresult==true)
      {
        *** return View();
      }
    }
  
    void Wservice_login_completed()
    {
        Here i got the output.
    }
  </code></pre>
  
  <p>But the calling of Wservice_login_completed() function was after the View*** was returned,, so I'm not getting the result. How do I achieve "calling webservice from Controller".. Any ideas? </p>