Share via


Reporting Services Web Services with .NET CORE 2

 

Any application built using .NET CORE SDK can be executed on any platform (Windows, Linux & Mac). But due to this there are a lot of APIs available in .NET Framework that are no longer available in .NET CORE. One of the missing APIs is Web Service (SOAP) Clients. The way to move forward is to use WCF Connected Services and create a BasicHttpBinding against Reporting Services Web Services.

 

In this blog, we will look at accessing the SSRS Web Services using .NET CORE and WCF Connected Services.

Reporting Services (ReportService2010.asmx):

1. Create a New Project - .NET Core (Console App)

 

2. To add a Connected Service Reference, the Extension needs to be added to Visual Studio. This isn’t install by Default.

  • Open Tools -> Extension and Updates
  • Search for “Microsoft WCF Web Service Reference Provider”
  • Download and Install – “Microsoft WCF Web Service Reference Provider”
  • Restart Visual Studio and Reopen the Project

3. Add a Connected Service and Choose “Microsoft WCF Web Service Reference Provider - Preview” :

 

4. Provide the Reporting Services Web Service URL: https://servername/Reportserver/ReportService2010.asmx

 

5. Enter the Namespace and click Finish

6. Update Program.cs with the following Code:

 using System;
using System.ServiceModel;
using System.Threading.Tasks;
using RSService;

namespace RSWcf
{
    class Program
    {
        static ReportingService2010SoapClient rsclient = null;

        static void Main(string[] args)
        {
            BasicHttpBinding rsBinding = new BasicHttpBinding();
            rsBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
            rsBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;

            EndpointAddress rsEndpointAddress = new EndpointAddress("https://servername/Reportserver/ReportService2010.asmx");

            rsclient = new ReportingService2010SoapClient(rsBinding, rsEndpointAddress);

            var output = rsListChildren("/");
            output.Wait();

            if(output.Status == TaskStatus.RanToCompletion && output.Result.Length > 0)
            {
                foreach(CatalogItem item in output.Result)
                {
                    Console.WriteLine(String.Format("Item Path: {0}", item.Path));
                }
            }

            Console.WriteLine("Completed!");
            Console.ReadLine();
        }

        private static async Task<CatalogItem[]> rsListChildren(String ItemPath)
        {
            TrustedUserHeader trustedUserHeader = new TrustedUserHeader();
            ListChildrenResponse listChildrenResponse = null;
            try
            {
                listChildrenResponse = await rsclient.ListChildrenAsync(trustedUserHeader, ItemPath, false);
            }
            catch(Exception exception)
            {
                Console.WriteLine(exception.Message + exception.StackTrace);
                return new CatalogItem[0];
            }
           return listChildrenResponse.CatalogItems;
        }
    }
}

7. Execute the Project, you would see an output like this:

 

8. To Publish the Project for all operating systems, execute this command:

 dotnet publish "C:\Projects\RSWcf\RSWcf.sln"

 

9. To Run the Application after publishing, execute this command:

 dotnet "C:\Projects\RSWcf\RSWcf\bin\Debug\netcoreapp2.0\RSWcf.dll"

 

 

Author:     Kane Conway – Support Escalation Engineer, SQL Server BI Developer team, Microsoft

Reviewer:   Krishnakumar Rukmangathan – Support Escalation Engineer, SQL Server BI Developer team, Microsoft

Comments

  • Anonymous
    June 19, 2018
    Hello!It will be great if you'll provide a full sample app. We are searching for one year an official microsoft solution for rendering rdl reports in out webpages.We aknowledge that asp.net core is cross platform, but we need a solution for windows hosting systems. In the currently scenario, we don't even use SQL Server Reporting Services... So why are we paying for licenses? We can easily use SQL Express and create our custom report pages (no rdl needed).
  • Anonymous
    October 29, 2018
    Thank you for this example. I was wondering if you could show an example of using the GetRendererResourceAsync . I need to download a report via .net core 2.1 code. The examples on the web to programmatically download are only available for .net framework.
  • Anonymous
    May 10, 2019
    Thanks for posing this sample. It helps.If anyone can point us to a code sample that includes 1) loading a parameterized report 2) executing the report in PDF format 3) saving the resulting PDF to an Azure File share, from a .NET Core 2 app built in Visual Studio 2017, we would be very grateful. This requirement was just imposed and of course delivery is expected immediately. No doc or sample we can find shows how to do this in NET Core 2. We're working on it independently and have asked for access to a relevant gitLab repo. Not much detailed doc on this out there, apparently. Thanks.