1. Create a WCF Service as in Creating and Accessing WCF Services simple sample.
2. Create Silverlight application.
3. Drag a textbox and Button from toolbox.
4. Add service reference.
5. Add the callback and button code.
Steps 2-5 show in the video below.
1. Generate asynchronous operations cannot be disable because Silverlight can only call WCF asynchronously.
2. Create a callback method.
public void svc_GetDataCompleted(object sender, ServiceReference1.GetDataCompletedEventArgs e)
textBox1.Text = e.Result;
3. Add code to button click event.
private void button1_Click(object sender, RoutedEventArgs e)
ServiceReference1.ServiceClient svc = new ServiceReference1.ServiceClient();
svc.GetDataCompleted += new EventHandler<ServiceReference1.GetDataCompletedEventArgs>(svc_GetDataCompleted);
4. You might need clientaccesspolicy.xml and crossdomain.xml files.
An error occurred while trying to make a request to URI ‘http://localhost/WCFService/Service.svc’. This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place, or a policy that is unsuitable for SOAP services. You may need to contact the owner of the service to publish a cross-domain policy file and to ensure it allows SOAP-related HTTP headers to be sent.