How to connect to Oracle database using WCF in Silverlight

In this article we will be seeing how to connect to the Oracle database using WCF in Silverlight and will perform a search to retrieve the data from the database, display them in the Silverlight data grid using Visual Studio 2010. In the Oracle database we will be having a table Employee Details with three columns Employee_ID, FirstName and LastName, having more than 10,000 data. Based on the Employee_ID we can search for the employees using this Silverlight search page.

Steps Involved:

Creating a Silverlight Application:

I. Open Visual Studio 2010.

ii. Go to File => New => Project.

iii. Select Silverlight from the Installed templates and choose the Silverlight Application template.

iv. Enter the Name and choose the location.


v. Click OK.

vi. In the New Silverlight Application wizard check the "Host the Silverlight Application in a new Web site".


vii. Click OK.

Adding WCF Service:

i. Right click on the asp.net website (in my case SilverlightApplicationSearchWebpartForOracle.web) which is automatically added to the Silverlight solution when we have created the Silverlight Application (If you check the Host the Silverlight application in a new Web site check box in the New Silverlight Application dialog box, an ASP.NET Web site is created and added to the Silverlight solution), select Add a new item.


ii. Select Web from the Installed templates and choose the WCF Service.

iii. Enter the Name for the service.


iv. Click OK.

v. Add the reference System.Data.OracleClient.

vi. Open IService1.cs.

vii. Replace the code with the following.

  1. using System;

  2. using System.Collections.Generic;

  3. using System.Linq;

  4. using System.Runtime.Serialization;

  5. using System.ServiceModel;