Link to home
Start Free TrialLog in
Avatar of nmiller61
nmiller61

asked on

C# with SSRS 2014 or 2016 creating scheduled reports

I have been working wtih SSRS and I like how you can create reports in the portal and even have subscriptions set up for reports to be ran automatically and emailed. Now I have a C# MVC web application I am building and I can display and run those SSRS reports. But I was trying to figure out how through my web application I could tie in maintaining and creating subscriptions to these SSRS reports so my users do not have to login and run the reports manually. I have searched the web but I have not found very good references. Any suggestions?
Avatar of Vadim Rapp
Vadim Rapp
Flag of United States of America image

...by the way, maybe an alternative you might want to look into is having the reports within your application itself. They are pretty much the same as on SSRS webserver, but "hosted" by the application itself. You can import .rdlc files into your project and have them viewed in reportviewer control, or printed directly.
Avatar of nmiller61
nmiller61

ASKER

I have looked at that link and this one https://msdn.microsoft.com/en-us/library/reportservice2010.reportingservice2010.createsubscription.aspx. I seem to have everything working but for the TrustedUserHeader parameter I get an
System.ServiceModel.Security.MessageSecurityException: 'The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'NTLM'.' error.

Not sure how to get around this one.

By the way I have been using the .rdlc files in my project for the most part. But a requirement I have in this upcoming project is for using to enter in when they want a report ran and emailed to them. It needs to be an automated process.

Thanks.
In the code sample that follows in your article, there are no headers. Try like in the sample.
I guess I do not understand what you mean by try like the sample there are no headers. When I implement the CreateSubscription method the first parameter is for TrustedUserHeader. I leave it null or pass in an empty TrusterUserHeader value and I get the error I mentioned above. I put my code below of just me trying to implement this in my Controller just as I am trying to get something to work. What am I doing wrong?

public ActionResult SSRSReports()
        {
            ReportingService2010SoapClient so = new ReportingService2010SoapClient();

            string report = "http://localhost" +
            "/ReportServer/SiteReport.rdl";

            string desc = "Send to Document Library";
            string eventType = "TimedSubscription";
            string scheduleXml =
               @"<ScheduleDefinition>" +
                "   <StartDateTime>2003-02-24T09:00:00-08:00" +
                "   </StartDateTime>" +
                "   <WeeklyRecurrence>" +
                "      <WeeksInterval>1</WeeksInterval>" +
                "      <DaysOfWeek>" +
                "         <Monday>True</Monday>" +
                "      </DaysOfWeek>" +
                "   </WeeklyRecurrence>" +
                "</ScheduleDefinition>";

            ParameterValue[] extensionParams = new ParameterValue[6];

            extensionParams[0] = new ParameterValue();
            extensionParams[0].Name = "RENDER_FORMAT";
            extensionParams[0].Value = "EXCEL";

            extensionParams[1] = new ParameterValue();
            extensionParams[1].Name = "FILENAME";
            extensionParams[1].Value = "Sales Order Detail";

            extensionParams[2] = new ParameterValue();
            extensionParams[2].Name = "FILEEXTN";
            extensionParams[2].Value = "True";

            extensionParams[3] = new ParameterValue();
            extensionParams[3].Name = "PATH";
            extensionParams[3].Value = "http://localhost" +
                "/ReportServer/";

            extensionParams[4] = new ParameterValue();
            extensionParams[4].Name = "WRITEMODE";
            extensionParams[4].Value = "Overwrite";

            extensionParams[5] = new ParameterValue();
            extensionParams[5].Name = "AUTOCOPY";
            extensionParams[5].Value = "False";

            string matchData = scheduleXml;
            ExtensionSettings extSettings = new ExtensionSettings();
            extSettings.ParameterValues = extensionParams;
            extSettings.Extension = "Report Server DocumentLibrary";

            try
            {

                TrustedUserHeader f = new TrustedUserHeader();
                string subid = null;

                so.CreateSubscription(f, report, extSettings, desc,
                eventType, matchData, null,out subid);
                
            }

            catch (SoapException e)
            {
                Console.WriteLine(e.Detail.InnerXml.ToString());
            }
            
            return View();
        }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Vadim Rapp
Vadim Rapp
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I guess you need to dumb this down for me to understand. Because I cannot seem to implement the solution found at https://msdn.microsoft.com/en-us/library/reportservice2010.reportingservice2010.createsubscription.aspx. If I add the ReportingService2010 rs = new ReportingService2010(); it shows that as not an object I can create.

Is it a simple tweak of my code I added earlier? You mentioned adding it as a wsdl but my question is How do I implement that?

Thanks.
solution explorer - references - add service reference
advanced
add web reference...
URL: http://<servername>/reportserver/ReportService2010.asmx
assign some meaningful name on the right

(There's also youtube video: https://www.youtube.com/watch?v=8tlChrfi2sM )

After that you will see new node "web references" in solution explorer, with your service. Then you can code it like in the article:

        Dim rr As New ReportService2010.ReportingService2010
        rs.Credentials = System.Net.CredentialCache.DefaultCredentials
(...)
        rs.CreateSubscription(report, extSettings, desc, eventType, matchData, Nothing)

Note that you don't need rs.URL  in code.
Perfect that worked great. Sorry I had always seen it used as a Service Reference. I can create another post but did you get this error when testing? I put a slash before my path and still get errors.
Message      "System.Web.Services.Protocols.SoapException: The path of the item 'http://localhost/ReportServer/SiteReport.rdl' is not valid. The full path must be less than 260 characters long; other restrictions apply. If the report server is in native mode, the path must start with slash. ---> Microsoft.ReportingServices.Diagnostics.Utilities.InvalidItemPathException: The path of the item 'http://localhost/ReportServer/SiteReport.rdl' is not valid. The full path must be less than 260 characters long; other restrictions apply. If the report server is in native mode, the path must start with slash.\n   at Microsoft.ReportingServices.Library.ReportingService2005Impl.CreateSubscription(String Report, ExtensionSettings ExtensionSettings, Boolean isDataDriven, DataRetrievalPlan DataRetrievalPlan, String Description, String EventType, String MatchData, ParameterValueOrFieldReference[] Parameters, Guid batchId, String& SubscriptionID)\n   at Microsoft.ReportingServices.Library.ReportingService2005Impl.CreateSubscription(String Report, ExtensionSettings ExtensionSettings, Boolean isDataDriven, DataRetrievalPlan DataRetrievalPlan, String Description, String EventType, String MatchData, ParameterValueOrFieldReference[] Parameters, String& SubscriptionID)\n   at Microsoft.ReportingServices.WebServer.ReportingService2010.CreateSubscription(String ItemPath, ExtensionSettings ExtensionSettings, String Description, String EventType, String MatchData, ParameterValue[] Parameters, String& SubscriptionID)"      string
Yes, quite frankly I spent about an hour on exactly this message :-)

Is your RS in sharepoint mode, or native? Find out. Don't assume that reports being availalble in sharepoint site means sharepoint mode.
I will create another post on this message. From my research it sounds like several others have this same question.

I am in Native mode.

Thanks again for all your help.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That fixed it!