Q:

How to get data (asynchronously) from WCF?

I have got the code that using WCF, requests data from the server.
For Example:
    public static Company LoadCompanyInfo(Guid session)
    {
        var client = new QualerServiceClient("QualerService");
        return client.GetCompanyInfo(session);
    }

I need to make my wpf application to run these code asynchronously.
I try:
    public static Company LoadCompanyInfoAsync(Guid session)
    {
        var client = new QualerServiceClient("QualerService");
        client.BeginGetCompanyInfo(session, new AsyncCallback(EndLoadCompanyInfoAsync), client);

        // How to Get Data from AsyncCallback function?
        return null;
    }

    private static void EndLoadCompanyInfoAsync(IAsyncResult r)
    {
        var client = r.AsyncState as QualerServiceClient;
        var result = client.EndGetCompanyInfo(r);
        // how to return the result value ??
    }

But I don't know how to return data from callback function.
I have got methods: 

BeginGetCompanyInfo and EndGetCompanyInfo
GetCompanyInfoAsync

and event:

GetCompanyInfoCompleted.

Quastions:

How can I get the data from the callback method?
What is the difference between GetCompanyInfoAsync and Begin\End? 
Best Practices: How can execute a method asynchronously, so that the GUI of my WPF App is not freezes?

A:

I'm assuming that you're using VS2012.
First, if your target is .NET 4.0, then install (via NuGet) the Async Targeting pack. If your target is .NET 4.5, you don't have to do anything special.
Next, re-create your client proxy. The existing Begin/End/Async endpoints will be replaced by a single Task<Company> GetCompanyInfoAsync(Guid).
Now you can use it like this:
public static Task<Company> LoadCompanyInfoAsync(Guid session)
{
  var client = new QualerServiceClient("QualerService");
  return client.GetCompanyInfoAsync(session);
}

public async void ButtonClickOrWhatever(...)
{
  var company = await LoadCompanyInfoAsync(mySession);
  // Update UI with company info.
}

The old Begin/End method pair was using the Asynchronous Programming Model (APM). The old Async/event pair was using the Event-based Asynchronous Programming model (EAP). The new Async method is using the Task-based Asynchronous Programming model (TAP). I have more information on async WCF on my blog.

