WCF Service as DataSource in SSRS

WCF Service as DataSource in SSRS

In this article, I will show you how to use WCF Service as Data Source in SSRS.

1. First of all create one WCF Service Application in visual studio 2010. In that service create one class named as Item. Let’s give DataContract attribute to class. Also add some properties with DataMember attribute in Class.

[DataContract]
public class Item
{
    [DataMember]
    public int ItemID { get; set; }

    [DataMember]
    public string ItemName { get; set; }

    [DataMember]
    public double ItemSales { get; set; }
}

1-WCF Service as DataSource in SSRS

2. Then create one OperationContract named as GetAllItems in IService1 Interface.

[ServiceContract]
public interface IService1
{
    [OperationContract]
    List GetAllItems();
}

2-WCF Service as DataSource in SSRS

3. Now in your Service1.svc class add two methods named as GetAllItems() and ItemData().

public List GetAllItems()
{
    return ItemData();
}

private List ItemData()
{
    List itemList = new List();

    itemList.Add(new Item { ItemID = 1, ItemName = "Bikes", ItemSales = 125000.00 });
    itemList.Add(new Item { ItemID = 2, ItemName = "Clothes", ItemSales = 100000.00 });
    itemList.Add(new Item { ItemID = 3, ItemName = "Cars", ItemSales = 75000.00 });

    return itemList;
}

3-WCF Service as DataSource in SSRS

4. To check WCF service, press F5 button. A WCF Test Client window opens. Invoke GetAllItems() method and see results like below screen shot.

4-WCF Service as DataSource in SSRS

So we have done with WCF Service. Now we use above WCF Service as DataSource in SSRS Report.

5. Now open Visual Studio 2010 and open your existing ssrs project or create a new project.

In that project crate new report named as DemoWCFServiceDataSource. Then create a new Data Source. To create a new data source, right click on Data Source in Report Data window and select Add Data Source.

A Data Source Properties window opens. In that select Embedded Connection and select XML from list of data source. In connection string text box enter following URL :

http://localhost:12140/Service1.svc 

In your case 12140 may be changed. so modify it as par your requirement.

5-WCF Service as DataSource in SSRS

6. Then right click on Datasets in Report Data window and select Add Dataset.

A Dataset Properties window opens. In that select DataSource and then click on Query Desinger. In Query Designer window enter following XML query into text box.

<Query>
<Method Namespace="http://tempuri.org/" Name="GetAllItems" />
<SoapAction>http://tempuri.org/IService1/GetAllItems</SoapAction>
</Query>

6-WCF Service as DataSource in SSRS

You can also check whether WCF Service returns data or not by clicking on Run button as shown in above screen shot. Then click on OK button.

7. Now right click on Report Area and go to Insert–>Table. Now select ItemID as Data field in 1st Column, ItemName in 2nd Column and ItemSales in Last Column.

so your report design looks like below :

7-WCF Service as DataSource in SSRS

8. To see the results click on preview tab. Your report should look like below screen shot :

8-WCF Service as DataSource in SSRS

Congratulations! We successfully completed use of  WCF Service as DataSource in SSRS

4 thoughts on “WCF Service as DataSource in SSRS

  1. Hi Bhushan,

    Is it possible to add another DataMember in current WCF?
    I have tried for it and it is throwing an error. In Report it is not binding.

  2. Hi Bhushan,
    I want to pass not only the column value, but also the DisplayName of the column through the web service. I am using a REST webservice and the xml looks like:

    value of col 1

    this works already, but I want something like:
    value of col
    Obviously, this is wrong xml (no spaces allowed), but even if I pass the DisplayName as attribute:
    …..
    I didn´t find a way in report builder to use the attribute as header, is there a way?

    thanks
    Joachim

Leave a Reply