RDLC report integration in ASP.NET Webforms using Object Data Source – SSRS

Standard

So in order to use SSRS reports in asp.net webforms application, following code comments should be taken care of:

1. Processing mode should be local in case of SSRS report
2. Object data source should be bind to class containing prototype of data access layer method
3. Empty data source object before each execution
4. set report parameter [if any]
5. set object data source parameter [if any]
6. set path of SSRS report
7. set method of object data source for processing of report
8. object data source id should be same as defined in client side / designer page [.aspx]
9. use same report data source which is used in SSRS report

Its done ūüôā

Client Side:

<rsweb:ReportViewer ShowWaitControlCancelLink=”false” ID=”ReportViewer”
runat=”server” Width=”100%” ProcessingMode=”Local”>
</rsweb:ReportViewer>
<asp:ObjectDataSource ID=”objDataSource” runat=”server”></asp:ObjectDataSource>

 

Server Side:

protected void btnShowReport_Click(object sender, EventArgs e)
{
ReportViewer.LocalReport.DataSources.Clear();

//Processing mode should be local in case of SSRS report
ReportViewer.ProcessingMode = ProcessingMode.Local;

ReportViewer.Attributes.Add(“style”, “margin-bottom: 30px;”);
ReportViewer.ShowParameterPrompts = false;
ReportParameter[] reportParameterList = new ReportParameter[2];

//Object data source should be bind to class containing prototype of data access layer method
objDataSource.TypeName = “BusinessLogic.SampleBusinnessMethods”;
objDataSource.SelectParameters.Clear();

//Empty data source object before each execution
ReportViewer.LocalReport.DataSources.Clear();

//set report parameter [if any]
reportParameterList[0] = new ReportParameter(“id1”, 2, false);
reportParameterList[1] = new ReportParameter(“id2”, 3, false);

//set object data source parameter [if any]
objDataSource.SelectParameters.Add(“id1”, TypeCode.Int32, “2”);
objDataSource.SelectParameters.Add(“id2”, TypeCode.Int32, “3”);

//set path of SSRS report
agentMonitorReportViewer.LocalReport.ReportPath = Server.MapPath(“Report.rdlc”);

//set method of object data source for processing of report
objDataSource.SelectMethod = “SelectMethodName”;

var rptDataSource = new ReportDataSource();

//object data source id should be same as defined in client side / designer page [.aspx]
rptDataSource.DataSourceId = “objDataSource”;

//use same report data source which is used in SSRS report
rptDataSource.Name = “ReportDataSet”;
ReportViewer.LocalReport.DataSources.Add(rptDataSource);
ReportViewer.LocalReport.SetParameters(reportParameterList);
ReportViewer.DataBind();
ReportViewer.LocalReport.Refresh();
}

Advertisements

Executing Web Method of ASP.NET Webforms using AngularJS services

Standard

The code written in legacy asp.net web application using webforms c# can be bit tricky to change into angualrJS application, however below angular factory method help to execute a server side WebMethod, method type can be changes to Get or Post as per need:

var app = angular.module('Sample', ['ngRoute']);

app.factory('appFactory', function ($templateCache, $http) {
    var factory = {};
    factory.populateData = function (webMethodUrl, parameterList) {
        return $http({
            method: "POST",
            url: window.location.protocol + '//' + window.location.host + 
                 window.location.pathname + webMethodUrl,
            data: parameterList,
            headers: { "Content-Type": "application/json" },
            responseType: 'json',
            cache: $templateCache
        });
    };
    return factory;
});

Enable WCF services for HTTPS Protocol

Standard

Once we had a service built on WCF framework in HTTP protocol, later on when client’s web based application is available on HTTPS after inclusion of SSL certificate, this service results in mixed mode computability issue for users. However this issue was resolved by defining a separate end point in webconfig file for HTTPS protocol.

<system.serviceModel>
<services>
<service name=”Service.eService” behaviorConfiguration=”DefaultServiceBehavior”>
<endpoint binding=”webHttpBinding” contract=”Service.IService”¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† behaviorConfiguration=”DefaultEPBehavior” bindingConfiguration=”HTTPsBinding” />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name=”DefaultEPBehavior”>
<webHttp/>
<CorsSupport/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name=”DefaultServiceBehavior”>
<serviceMetadata httpGetEnabled=”true”/>
<serviceDebug includeExceptionDetailInFaults=”true”/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name=”HTTPsBinding”>
<security mode=”Transport”>
</security>
</binding>
</webHttpBinding>
</bindings>
<extensions>
<behaviorExtensions>
<add name=”CorsSupport” type=”Service.CorsSupportBehaviorElement, App_Code”/>
</behaviorExtensions>
</extensions>
<serviceHostingEnvironment multipleSiteBindingsEnabled=”true”/>
</system.serviceModel>

 

Note: Key thing to mention here is to define a new endpoint for HTTPS domain in web config of WCF project, bindingConfiguration=”HTTPsBinding” this will do the magic !!!