We help IT Professionals succeed at work.

Getting Data from a WCF Application

VBBRett used Ask the Experts™
I am trying to learn WCF right now and I am trying to pull data using a WCF solution.  Not sure how to do it, how can I do it using an OLEDB connection to a SQL Server 2000 database?  Thanks!
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior consultant
For a simplified version if you already have an existing data layer or if you dont and know how to create one, do that as usual and then you wrap that in a wcf service which would consist of a host layer, proxy layer and service layer your service layer would simply consume your data layer library exposing only what you wish, your host layer would expose your service layer via whatever protocol you choose to use and your proxy layer is only optional if you wish to use the api as apose to adding a web reference.

That would be the simplified way to do it but myself personal would implement an SOA architecture, hope that helps.


Do you by any chance have any samples of code?
1) Setting Oledb connection :

First, import the "System.Data.OleDb" namespace in your WCF service class then add below code. Please make the changes accordingly -

dim dbconn,sql,dbcomm,dbread
dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
data source=" & server.mappath("northwind.mdb"))
sql="SELECT * FROM customers"
dbcomm=New OleDbCommand(sql,dbconn)

2) Calling the service using jSon
jQuery functionsyntax to call the service from .aspx page

// Function to call WCF  Service      
function CallService() {
        type: Type, //GET or POST or PUT or DELETE verb
        url: Url, // Location of the service
        data: Data, //Data sent to server
        contentType: ContentType, // content type sent to server
        dataType: DataType, //Expected data format from server
        processdata: ProcessData, //True or False
        success: function(msg) {//On Successfull service call
        error: ServiceFailed// When Service call fails

Check the complete sample application at