ReportingServices2010.FireEvent,订阅参数

时间:2013-06-19 20:30:09

标签: c# reporting-services ssrs-2012

我设置了一份SSRS报告,其中包含一个向Windows共享输出PDF的订阅。我的问题是这个。我需要在报告订阅中添加1个报告参数,并且能够让用户触发'订阅基于他们定义的参数。 (让他们访问报告服务站点不是一种选择)。

My Current思想涉及在.NET中编写可以使用FireEvent方法触发订阅的应用程序,但是我不知道如何能够以这种方式将参数传递给订阅。我已经在ReportingServices2010课程中研究了其他各种方法,但我绝对不知所措,并且已经放弃了对这个网站的智慧。

以下是我目前正在使用的代码,该代码效果很好,但我需要展开它或更改它:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SSRSReportGenerator.SRSWebService;

namespace SSRSReportGenerator
{
class Program
{
    static void Main(string[] args)
    {
        ReportingService2010 rs = new ReportingService2010();
        rs.Url = "http://server/ReportServer/ReportService2010.asmx";
        rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

        //set report properties
        string site = "/report/report";

        // Get the subscription
        Subscription[] subs = rs.ListMySubscriptions(site);

        try
        {                
            //specify null for siteURL if native mode
            rs.FireEvent("TimedSubscription", subs[0].SubscriptionID, null);
            Console.WriteLine("Event fired.");

        }

        catch (Exception e)
        {
            Console.WriteLine(e.Message);
            Console.ReadKey();
        }
    }
}
}

再次感谢大家!

1 个答案:

答案 0 :(得分:3)

如果您打算从C#程序中解除计划,为什么还要打扰计划呢?只需直接从您的程序中运行带有参数的报告即可。这很容易Microsoft have some example code to get you started

using System;
using System.IO;
using System.Web.Services.Protocols;
using myNamespace.MyReferenceName;

class Sample
{
    static void Main(string[] args)
    {
        ReportExecutionService rs = new ReportExecutionService();
        rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
        rs.Url = "http://myserver/reportserver/ReportExecution2005.asmx";

        // Render arguments
        byte[] result = null;
        string reportPath = "/AdventureWorks Sample Reports/Employee Sales Summary";
        string format = "MHTML";
        string historyID = null;
        string devInfo = @"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>";

        // Prepare report parameter.
        ParameterValue[] parameters = new ParameterValue[3];
        parameters[0] = new ParameterValue();
        parameters[0].Name = "EmpID";
        parameters[0].Value = "288";
        parameters[1] = new ParameterValue();
        parameters[1].Name = "ReportMonth";
        parameters[1].Value = "6"; // June
        parameters[2] = new ParameterValue();
        parameters[2].Name = "ReportYear";
        parameters[2].Value = "2004";

        DataSourceCredentials[] credentials = null;
        string showHideToggle = null;
        string encoding;
        string mimeType;
        string extension;
        Warning[] warnings = null;
        ParameterValue[] reportHistoryParameters = null;
        string[] streamIDs = null;

        ExecutionInfo execInfo = new ExecutionInfo();
        ExecutionHeader execHeader = new ExecutionHeader();

        rs.ExecutionHeaderValue = execHeader;

        execInfo = rs.LoadReport(reportPath, historyID);

        rs.SetExecutionParameters(parameters, "en-us"); 
        String SessionId = rs.ExecutionHeaderValue.ExecutionID;

        Console.WriteLine("SessionID: {0}", rs.ExecutionHeaderValue.ExecutionID);


        try
        {
            result = rs.Render(format, devInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);

            execInfo = rs.GetExecutionInfo();

            Console.WriteLine("Execution date and time: {0}", execInfo.ExecutionDateTime);


        }
        catch (SoapException e)
        {
            Console.WriteLine(e.Detail.OuterXml);
        }
        // Write the contents of the report to an MHTML file.
        try
        {
            FileStream stream = File.Create("report.mht", result.Length);
            Console.WriteLine("File created.");
            stream.Write(result, 0, result.Length);
            Console.WriteLine("Result written to the file.");
            stream.Close();
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
        }

    }
}