Monday, January 26, 2009

Using Report Services 2005 Web Service

EDIT: Your problem may be easily solved if you read this first http://alsaydi.blogspot.com/2010/11/consuming-reporting-services-2005-web.html 

Today I wrote a very simple application that connects to Reporting Services 2005 web service.
The Web Services URL is:

http://[servername]/ReportServer/ReportService2005.asmx

Many sources give the following lines of code as a sample (assuming you have all the proper using statements)

ReportingService2005 rs = new ReportingService2005();
rs.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
CatalogItem [] items = rs.ListChildren("/Sales Reports", true);

I first tried this with Visual Studio 2008 and noticed that there is no ReportingService2005 class. The closes class ReportingService2005SoapClient. So I switched to Visual Studio 2005 and the VS IntelliSense showed ReportingService2005 and my code worked.

After a some time of playing around I found a way to get the code to work in VS2008.

The app.config file of t he VS2008 a couple of changes needs to be made:

the binding tage , the property allowCookies has to be set true (I think not sure)


<security mode="TransportCredentialOnly">                                          
<transport clientCredentialType="Windows" proxyCredentialType="Windows"
realm="" />
</security>



This simple will use Windows integrated authentication.
One more line of code is need to allow impersonation:
rs.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;

assuming rs is an instance of ReportingService2005SoapClient.

So a sample code looks something like the following:

ReportingService2005SoapClient rs = new ReportingService2005SoapClient();
rs.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
CatalogItem[] items;
rs.ListChildren("/", true, out items);
dataGridView1.DataSource = items;

Cool things can be done through RS2005 Web Service!

4 comments:

  1. Thank you so much. I couldn't find any other examples in 2008 online and was getting rather frustrated! Awesome example.

    ReplyDelete
  2. Nice...In my case I had to use Ntlm


    ReplyDelete