JG Vimalan's Blog

It is all about coding!

Consuming WCF service in Silverlight application

In order to consume WCF service in your silverlight application, add the WCF Service as a service reference in your Silverlight application. Once you do that, you can see a ServiceReferences.ClientConfig file in your silverlight project. It will have the binding information and the endpoint as shown below,

                <binding name=”basicEndPoint” maxBufferSize=”2147483647″ maxReceivedMessageSize=”2147483647″>
                    <security mode=”None” />
            <endpoint address=”http://mySystem/WCFService/Manager.svc” binding=”basicHttpBinding”
                bindingConfiguration=”basicEndPoint” contract=”SampleWCFService.IManager”
                name=”basicEndPoint” />

So, its time to invoke the methods exposed by the WCF service. In silverlight, it is slightly different when compared to asp.net web application. You will call the asynchronous method and handle its completed event, where you get the result.

private void button1_Click(object sender, RoutedEventArgs e)
            SampleWCFService.ManagerClient client = new

            client.GetEmployeesCompleted += new

            client.GetEmployeesAsync(); //invoke the GetEmployees method here

        void client_GetEmployeesCompleted(object sender, SampleWCFService.GetEmployeesCompletedEventArgs e)
            //you will get the result object here
            System.Collections.ObjectModel.ObservableCollection<SampleWCFService.Employee> employees =

            if (employees.Count() > 0)
                //put code here

October 21, 2010 - Posted by | Silverlight, WCF

1 Comment »

  1. great blog

    Comment by bradshaw | December 2, 2010 | Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: