Saturday, October 31, 2015

Why ReportViewer Control not working on IIS 7?





Symptoms:
  •  Unable to render ReportViewer in ASP.NET Web Pages while running on IIS7.
  •  You are able to view your reports on Report Manager as well as while you are debugging locally  but not able to view them on IIS7.
  •  You encounter JavaScript error when loading your report page with ReportViewer. Image buttons such as calendar appear as red ‘X’.
Cause:
  • When you add ReportViewer control is into web page(.aspx), the
    Reserved.ReportViewerWebControl.axd httpHandler is added to System.Web section of the Web.Config file. In IIS7, It should be added under System.WebServer section.
  • IIS7  Handler Mappings doesn’t contain Reserved.ReportViewerWebControl.axd httpHandler, and that’s why not able to render the some ReportViewer elements which is needed by the JavaScript.
Solution : 
1. Open Internet Information Services (IIS) Manger and select Default Web Site.
2. Under IIS Section, Double click on Handler Mappings.
1-Why ReportViewer Control not working on IIS 7
3. From Action Pane (Right Side of Handler Mappings Section), click on Add Managed Handler.
2-Why ReportViewer Control not working on IIS 7
4. Add Managed Handler dialog opens. In that, enter following values.
Request Path : Reserved.ReportViewerWebControl.axd
Type :Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Name : Reserved-ReportViewerWebControl-axd
3-Why ReportViewer Control not working on IIS 7
Then click on OK button.
Reserved-ReportViewerWebControl-axd handler is now added to your Handler Mappings list. Also notice that the following line has also been added to your application’s Web.config file under the system.webserver’s handler section:
<add name=”Reserved-ReportViewerWebControl-axd” path=”Reserved.ReportViewerWebControl.axd” verb=”*” type=”Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a” resourceType=”Unspecified” preCondition=”integratedMode” />
Now try to run your report again.

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.
?
1
2
3
4
5
6
7
8
9
10
11
12
[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 IService1Interface.
?
1
2
3
4
5
6
[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().
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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.
?
1
2
3
4
<Query>
<Method Namespace="http://tempuri.org/" Name="GetAllItems" />
</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 ItemIDas 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