Getting WCF to work in Silverlight

Here are the steps to get the WCF calls to work in silverlight.

1.create a website hosted in IIS and create a WCF service, change the Binding to basicHttpBinding in Web.Config file

2.Add Silverlight project to the solution and select(‘link this control to existing website’) and set the  website from the dropdown

3. Add ServiceReference in silverlight project. In Page1.xaml.cs, the code will look similar to this

 public Page()
            BasicHttpBinding binding = new BasicHttpBinding();
            EndpointAddress address = new EndpointAddress(“http://localhost/mywebsite/myservice.svc“);
            ServiceReference1.MyServiceClient client = new SilverlightApplication1.ServiceReference1.MyServiceClient(binding, address);
            client.DoWorkCompleted += new EventHandler<SilverlightApplication1.ServiceReference1.DoWorkCompletedEventArgs>(client_DoWorkCompleted);


        void client_DoWorkCompleted(object sender, SilverlightApplication1.ServiceReference1.DoWorkCompletedEventArgs e)
            //handler code



3 thoughts on “Getting WCF to work in Silverlight

  1. Hey,
    I am trying to see if Silverlight 2 would play nice with a SOA architecture.
    So I have a WCF service layer.
    And I am doing something similar to the code you have up there. But I am having little trouble with a “stupid” thing, How do I make the end point in config file. there are no config files apparently in Silverlight, because if I understand it’s running on the client machine.
    What am I missing?
    Do you even think what we’re trying to do here is the way to go, if we’re using silverlight

  2. I dont think config files are supported in this release. that is the reason we are creating EndPointAddress in code. I think WCF is the recommended way

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s