1

我有一个 SSRS 报告设置了一个订阅,该订阅将 PDF 输出到 Windows 共享。我的问题是这个。我需要向报告订阅添加 1 个报告参数,并且能够让用户根据他们定义的参数“触发”订阅。(让他们访问报告服务站点不是一种选择)。

我目前的想法涉及在 .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();
        }
    }
}
}

再次感谢大家!

4

1 回答 1

3

如果您要从 C# 程序中触发日程安排,为什么还要为日程安排而烦恼呢?只需直接从程序中使用您的参数运行报告即可。这很容易,Microsoft 有一些示例代码可以帮助您入门

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);
        }

    }
}
于 2013-06-20T01:00:39.330 回答