2013-06-19 68 views
0

我有一個SSRS報告,它設置了一個將PDF輸出到Windows共享的訂閱。我的問題是這個。我需要爲報告訂閱添加1個報告參數,並且能夠根據用戶定義的參數讓用戶「觸發」訂閱。 (讓他們訪問報告服務網站不是一種選擇)。ReportingServices2010.FireEvent,訂閱參數

我當前的想法涉及到使用FireEvent方法在.NET中編寫一個可以觸發訂閱的應用程序,但是我不知道如何能夠以這種方式將參數傳遞給訂閱。我已經研究過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(); 
     } 
    } 
} 
} 

再次謝謝大家!

回答

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

    } 
} 
+0

的ReportServiceExecution類爲我做!謝謝你指出我朝着正確的方向。 – user2502795