SilverLight WCF Integration

WCF is used to make the communication in the intranet projects and in the internet projects, the Microsoft  design ned WCF using distributed technology and using standard based technology

     Distributed Technology                                                                      




Standard based technology


The Microsoft designed remoting with distributed technology, In the remoting always we have to implement threes different application

  1. Private assembly
  2. Server application
  3. Client application

The private assembly dll file features we have to distribute to the server application and to the client application

The Microsoft designed web services using standard based technology, using web services we can make the communication in the intranet project and in the internet projects.

Web service designed in the special type of proxy machines(middle wares)

The web service implemented persons distributing web URL to the main project, based on web URL we can access web service features in the remote location.

While working with WCF integration in the silver light application, we have to open silverlight application hosting page as webpage, while opening the project the Microsoft given two different projects in the single application

  1. Silverlight application
  2. net application

We have to implement WCF service in the folder, while adding WCF service in the project automatically getting two files

  1. I service 1. Cs
  2. Service 1. SVC.Cs

I service 1.cs :  The Microsoft given predefined interface in the iservice 1.cs fiel, we have to declare methods in the interface

Service 1. Svs.cs:  the Microsoft given predefined class in the  service 1. Svc.cs file, in the predefined class we should have to implement all interface methods.

After implementing the service class methods we have to execute service 1. Svc file, getting service reference, by adding this reference in the intranet projects and in the internet projects we can distribute WCF service features.

Client access policy. Xml:  This file is used to grant cross domain features to the WCF service.

The WCF service reference we have to add in the silver light application

Import the WCF namespace

Create instance to the WCF service class

Déclassé the event

Define the event

Call the WCF service method

Example on WCF Integration with SilverLight

Open new silver light application with webpage as hosting page.

Add text box and button control in the main page. XAML file

Add WCF service

Go to solution explorer window right click on the folder select add à click on new item à select WCF service à click on add button

Declaring methods in the iservice interface

Go to iservice 1. Cs file module

[service contract]

Public interface iservice1


[operation contract]

String addstr();

[operation contract]

Void dowork();


Implementing iservice interface methods in the service class

Go to service 1. SVC.CS file module

Public class service 1: iservice1


Public void do work ()



Public string addstr()


Return “from WCF”;


To give cross domain features to the WCF service we have to add XML file name with ‘ client accesspolicy. XML’


Adding XML file: Go to solution explorer window right click on the folder select add à click on new item, select XML file click on add button

Go to XML file module

<? XML version  = “1.0” encoding = “utf  - 8” ? >

<access – policy>

<cross – domain –access>


<allow- from http_request _headers = “*”>

<domain uri = “*”/>

</allow _from>

<grant – to>

<resource include _ subpaths = “true” path = “/” />

</grant – to>


</cross _ domain – access>

</access – policy>

Execute service 1. Svc file, getting service rul

As per this application service url is

http: //loathes: 1033/ servicel.svc