6 Tips of Separation: Listing 1.
Asynchronous calls to a WCF service.
- By Benjamin Day
- 04/01/2011
public void LoadById(int id)
{
// Create an instance of the service proxy
var client = new PersonService.PersonServiceClient();
// Subscribe to the "completed" event for the service method
client.LoadByIdCompleted +=
new EventHandler<PersonService.LoadByIdCompletedEventArgs>(
client_LoadByIdCompleted);
// Call the service method
client.LoadByIdAsync(id);
}
void client_LoadByIdCompleted(object sender,
PersonService.LoadByIdCompletedEventArgs e)
{
// This method is called after the call to LoadByIdAsync() is finished
PersonService.PersonDtopersonReturnedByService = e.Result;
// ...
}
About the Author
Benjamin Day is a consultant, trainer, and author specializing in software development, project management, and leadership. Ben’s main areas of emphasis include Azure DevOps, C#, Angular, Scrum, software testing, and software architecture. He is a Microsoft MVP, a certified Scrum trainer via Scrum.org, and speaks regularly at VSLive. His online courses are available at YouTube and at http://www.pluralsight.com. Ben is also the founder of https://SlideSpeaker.ai. He can be contacted via http://www.benday.com.