title: Invoke operation in wcf ria service
body: <p>I use some invoke operation method in wcf ria service.like following method:</p>
  
  <pre><code>    [Invoke]
      public int GetCountOfAccountsByRequestId(long requestId)
      {
          return ObjectContext.Accounts.Count(a =&gt; a.RequestId ==requestId);
      }
  </code></pre>
  
  <p>When i want get data from this method , i use the following code to run and get value from invoke method:</p>
  
  <pre><code>        int countOfAccounts = 0;
          InvokeOperation&lt;int&gt; invokeOperation = context.GetCountOfAccountsByRequestId(selectedRequest.RequestId);
  
          invokeOperation.Completed += (s, args) =&gt;
                                           {
                                               if (invokeOperation.HasError)
                                               {
                                                   var messageWindow = new MessageWindow(invokeOperation.Error.Message);
                                                   messageWindow.Show();
                                                   invokeOperation.MarkErrorAsHandled();
                                               }
                                               else
                                               {
                                                   countOfAccounts = invokeOperation.Value;
  
  
                                                   if (countOfAccounts == 0)
                                                   {
  
                                                       // do some thing
  
                                                   }
                                               }
                                           };
  </code></pre>
  
  <p>But this method requires a lot of coding to Run invoke method and get value from this.Also as part of this code is executed asynchronously.Similarly, some method must be implemented in tandem.And the return value of each method is related to previous methods.<br></p>
  
  <p>How can i implement this actions?!
  How can i write better than this without any problem?</p>