Académique Documents
Professionnel Documents
Culture Documents
.NET Projects DVD @ 600 INR includes Invoicing Application end to end project using SDLC
cycle for details of the contents log‐on to www.questpond.com
Sharepoint, WCF, WPF, WWF, LINQ & SharePoint Videos @ 1000 INR for details of the
contents log‐on to www.questpond.com
• Introduction
• Step 1: Create Your WCF Service
• Step 2: Enable Cross Domain for Your WCF Service
• Step 3: Add the WCF Service Reference
• Step 4: Call the Service
Introduction
This article will talk about 4 simple steps which will assist you to consume WCF service in a
Silverlight application. It also has a simple sample source code which demonstrates all the 4
steps practically.
I have collected around 400 FAQ questions and answers in WCF, WPF, WWF, SharePoint,
design patterns, UML, etc. Feel free to download these FAQ PDFs from my site
http://www.questpond.com/.
The first step is to create your WCF service. When we create a WCF service, by default it
creates ‘GetData’ function which takes in an integer value and returns back a string
saying “You entered 10” , in case you passed ‘10’ as value to the function. We will try to
consume this service in Silverlight in the coming steps:
For this example, our WCF service and the Silverlight web application will be hosted in
different IIS websites. In other words, they will be hosted in different domains. When we
talk about different website, in other words they are hosted in different domains. For
instance, it’s possible that your Silverlight web application is hosted in one domain like
http://www.xyz.com/ and your WCF service is hosted in different domain i.e.
http://www.pqr.com/.
The WCF service needs to enable cross domain facility so that other domains can consume
the WCF service.
Figure: Cross domain
We need to create two XML files (clientaccesspolicy.xml and crossdomain.xml) in the root
directory of the WCF service to enable cross domain functionality.
Below is the XML code snippet for clientaccesspolicy.xml:
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM
"http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-http-request-headers-from domain="*" headers="*"/>
</cross-domain-policy>
Step 3: Add the WCF Service Reference
Create a simple Silverlight application and add the service reference to your Silverlight
project. In order to call the WCF service, we need to define event handlers.
One of the important points to note is that the function ‘GetData’ is called asynchronously.