Sunday 27 June 2010

WCF Service method async call from Silverlight project.

There are three steps to call a WCF service from silverlight project.

1. Create WCF service client instance.

PCSalesOfficeServiceClient _PCSalesOfficeServiceClient = new PCSalesOfficeServiceClient();

2. To catch asynchronous call response we have to use delegates. For every method of WCF service there is a completed event and an asynchronous method. So initially we will assign completed event of any WCF methods.

_PCSalesOfficeServiceClient.SaveSalesOfficeCompleted += new EventHandler<SaveSalesOfficeCompletedEventArgs>(_PCSalesOfficeServiceClient_SaveSalesOfficeCompleted);

3. Finally we will make call where it is necessary. For every call there is a completed event, no matter what is return type of calling method. To catch completed event we have to follow step two.

_PCSalesOfficeServiceClient.SaveSalesOfficeAsync(_SalesOffice);