title: WCF Synchronous vs Asynchronous
body: <p>I have been looking at MSDN and codeproject, but I am still a bit confused.</p>
  
  <p>Synchronous Service vs an Asynchronous service.</p>
  
  <p>I have a WCF service end point. This service has a 2way SSL applied to its web.config file.
  The client end point is a Oracle based java Weblogic Suite. This has its own private key and public key. The client needs to communicate with our service both asynchronously and synchronously.</p>
  
  <p><strong>I CAN ONLY CHANGE THINGS ON THE SERVER SIDE</strong></p>
  
  <p><a href="http://www.codeproject.com/Articles/91528/How-to-Call-WCF-Services-Synchronously-and-Asynchr" rel="nofollow">http://www.codeproject.com/Articles/91528/How-to-Call-WCF-Services-Synchronously-and-Asynchr</a></p>
  
  <p><a href="http://msdn.microsoft.com/en-us/library/ms731177.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms731177.aspx</a></p>
  
  <p>The following code is the synchronous part of the SVC, cs file:-</p>
  
  <pre><code>public getQuoteSyncResponse1 getQuoteSync(getQuoteSyncRequest request)
       {
          // Create new response
          getQuoteSyncResponse1 res = new getQuoteSyncResponse1();
  
          res.GetQuoteSyncResponse = new GetQuoteSyncResponse();
          res.GetQuoteSyncResponse.Header = new GetQuoteResponseHeaderType();
          res.GetQuoteSyncResponse.Response = new GetQuoteSyncResponseType();
  
          // Create and populate header
          res.GetQuoteSyncResponse.Header.MessageId = request.GetQuoteRequestSync.Header.MessageId;
          res.GetQuoteSyncResponse.Header.Timestamp = request.GetQuoteRequestSync.Header.Timestamp;
          res.GetQuoteSyncResponse.Header.QuoteId = request.GetQuoteRequestSync.Header.QuoteId;
          res.GetQuoteSyncResponse.Header.CarrierId = request.GetQuoteRequestSync.Header.CarrierId;
  
  
          List&lt;RejectionType&gt; rj = new List&lt;RejectionType&gt;();
  
  
          string _sTotalEmployees = request.GetQuoteRequestSync.Request.Employer.TotalEmployees;
          int _TotalEmployees = 0;
          if (int.TryParse(_sTotalEmployees, out _TotalEmployees) == false)
          {
  
  
              RejectionType rt;
              rt = new RejectionType();
              rt.ReasonCode = "R01";
              rt.ReasonDescription = "Invalid Number of Employees";
  
              rj.Add(rt);
  
              res.GetQuoteSyncResponse.Response.Rejections = rj.ToArray();
  
              res.GetQuoteSyncResponse.Response.ReceiptStatus = AcceptanceContentType.Reject;
  
              return res;
          }
  
          res.GetQuoteSyncResponse.Response.ReceiptStatus = AcceptanceContentType.Success;
  
          List&lt;QuoteType&gt; q = new List&lt;QuoteType&gt;();
  
          QuoteType qt;
  
          qt = new QuoteType();
          qt.PlanId = "P345678";
          qt.EEPremium = 1220;
          qt.EESPPremium = 2222;
          qt.EEDepPremium = 3333;
          qt.EEFamilyPremium = 4444;
          qt.TotalMonthlyPremium = 3456;
          qt.CoverageEffectiveDate = DateTime.Now;
  
          q.Add(qt);
  
          res.GetQuoteSyncResponse.Response.Quotes = q.ToArray();
  
          return res;}
  </code></pre>
  
  <p>so this Synchronous part of the service is working. Now, how do I use this to transform it into the asynchronous equivalent?</p>
  
  <p>Should I be starting the async method in the cs file? or in the svc file? I am confused...</p>
  
  <pre><code> public getQuoteAsyncResponse getQuoteAsync(getQuoteAsyncRequest request, AsyncCallback callback, Object state)
      {
          // Create new response
          getQuoteAsyncResponse res = new getQuoteAsyncResponse();
  
          return new getQuoteAsyncResponse();
      }
  </code></pre>
  
  <p>I sort of understand about the callback deli-gator, object state and such, but can someone illustrate this further for me? How do I format the asynchronous part of the service? The web has so many examples... but all very confusing. I must have some inherent misunderstanding on this concept.</p>
  
  <p><em><strong>Edit:- I was told in the answer that, the server side needs no manipulation for async style of communication. However I found this:-</em></strong></p>
  
  <p>Implementing Asynchronous Operations in WCF 
  Just as the WCF plumbing enables clients to call server operations asynchronously, without the server needing to know anything about it, WCF also allows service operations to be defined asynchronously. So an operation like:</p>
  
  <pre><code>[OperationContract]
  string DoWork(int value);
  </code></pre>
  
  <p>…might instead be expressed in the service contract as:</p>
  
  <pre><code>[OperationContract(AsyncPattern = true)]
  IAsyncResult BeginDoWork(int value, AsyncCallback callback, object state);
  
  string EndDoWork(IAsyncResult result);
  </code></pre>
  
  <p>Note that the two forms are equivalent, and indistinguishable in the WCF metadata: they both expose an operation called DoWork[1]:</p>