Faced this scenario where I had to access a report programatically, so that I can render it to some pdf or Excel.

Here are the Steps:

1. Create a new console application and add following web-references:

a. http://Reportserver_/ ReportService2005.asmx as ReportService
b. http://Reportserver_/ ReportExecution2005.asmx as ReportExecution


namespace abc{

class Program
{
static void Main(string[] args)
{

ReportingService2005 rs = new ReportingService2005();
ReportExecutionService rsExec = new ReportExecutionService();

rs.Url = "http:///reportserver_/reportservice2005.asmx";
rsExec.Credentials = new System.Net.CredentialCache.DefaultCredentials;
rsExec.Url = "http:///reportserver_/ReportExecution2005.asmx";

ExecutionInfo execInfo = new ExecutionInfo();
TrustedUserHeader trusteduserHeader = new TrustedUserHeader();
ExecutionHeader execHeader = new ExecutionHeader();
abc.ReportExecution.ServerInfoHeader serviceInfo = new abc.ReportExecution.ServerInfoHeader();
try
{
string _report = string.Empty;
string _history = string.Empty;
_report = "";

execInfo = rsExec.LoadReport(_report, null);
}

catch (Exception exp)
{
throw;
}
}

}

By doing all this, if we run the program, it will fail with ItemNotFoundException “that item at cannot be found”

Reason is the reports in crm are meant to be used for internal purpose only. {If we go to Report server and execute report from there, it prompts for credentials}

To reference the reports externally : Go to Reports –> Select report –> Edit Report –> Actions –> Publish Report for External use.

This will create a copy of report outside 4.0 folder on Report Server for CRM.{Now if we run this new copy of report, it will run without asking for credentials}

Now run the console application again and it should work fine.

I am still looking how to handle data filtering based on security roles. Will update this once I get the details.

Hope this helps someone.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s