ReportExecutionService.Render 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
處理特定報告並以指定格式呈現。
public:
cli::array <System::Byte> ^ Render(System::String ^ Format, System::String ^ DeviceInfo, [Runtime::InteropServices::Out] System::String ^ % Extension, [Runtime::InteropServices::Out] System::String ^ % MimeType, [Runtime::InteropServices::Out] System::String ^ % Encoding, [Runtime::InteropServices::Out] cli::array <ReportExecution2005::Warning ^> ^ % Warnings, [Runtime::InteropServices::Out] cli::array <System::String ^> ^ % StreamIds);
public byte[] Render(string Format, string DeviceInfo, out string Extension, out string MimeType, out string Encoding, out ReportExecution2005.Warning[] Warnings, out string[] StreamIds);
member this.Render : string * string * string * string * string * Warning[] * String[] -> byte[]
Public Function Render (Format As String, DeviceInfo As String, ByRef Extension As String, ByRef MimeType As String, ByRef Encoding As String, ByRef Warnings As Warning(), ByRef StreamIds As String()) As Byte()
參數
- Format
- String
報告的格式。 此參數對應到渲染擴充。 支援的擴充功能包括 XML、NULL、CSV、IMAGE、PDF、HTML4.0、HTML3.2、MHTML、Excel 及 Word。 呼叫該 ListRenderingExtensions() 方法可獲得支援擴充功能的清單。
- DeviceInfo
- String
一個包含參數中指定 Format 渲染擴充所需的裝置特定內容的 XML 字串。 DeviceInfo 設定必須作為 DeviceInfo XML 元素的內部元素傳遞。 欲了解更多特定輸出格式的裝置資訊設定,請參閱「將裝置資訊設定傳遞給渲染擴充」。
- Extension
- String
[出]對應輸出串流的檔案副檔名。
- MimeType
- String
[出]呈現報告的 MIME 類型。
- Encoding
- String
[出]報告伺服器渲染報告內容時所使用的編碼方式。
- StreamIds
- String[]
[出]串流識別碼。 這些 ID 會傳給方法。RenderStream(String, String, String, String, String) 你可以用它們來渲染與報告相關的外部資源(圖片等)。
若使用 IMAGE 渲染擴充,該方法會輸出一個空陣列。StreamIds
傳回
報告的 位元組[] 陣列,格式依規定。
範例
要編譯以下程式碼範例,您必須參考 Reporting Services WSDL 並匯入特定命名空間。 欲了解更多資訊,請參閱編 譯與執行程式碼範例。 以下程式碼範例以 MHTML 渲染報告,並將其儲存為 .mht 檔案至磁碟。
Imports System
Imports System.IO
Imports System.Web.Services.Protocols
Imports myNamespace.MyReferenceName
Class Sample
Public Shared Sub Main()
Dim rs As New ReportExecutionService()
rs.Credentials = System.Net.CredentialCache.DefaultCredentials
rs.Url = "http://myserver/reportserver/ReportExecution2005.asmx"
' Render arguments
Dim result As Byte() = Nothing
Dim reportPath As String = "/AdventureWorks Sample Reports/Employee Sales Summary "
Dim format As String = "MHTML"
Dim historyID As String = Nothing
Dim devInfo As String = "<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"
' Prepare report parameter.
Dim parameters(2) As ParameterValue
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"
Dim credentials As DataSourceCredentials() = Nothing
Dim showHideToggle As String = Nothing
Dim encoding As String = ""
Dim mimeType As String = ""
Dim warnings As Warning() = Nothing
Dim reportHistoryParameters As ParameterValue() = Nothing
Dim streamIDs As String() = Nothing
Dim execInfo As New ExecutionInfo
Dim execHeader As New ExecutionHeader()
Dim SessionId As String
Dim extension As String = ""
rs.ExecutionHeaderValue = execHeader
execInfo = rs.LoadReport(reportPath, historyID)
rs.SetExecutionParameters(parameters, "en-us")
SessionId = rs.ExecutionHeaderValue.ExecutionID
Console.WriteLine("SessionID: {0}", rs.ExecutionHeaderValue.ExecutionID)
Try
result = rs.Render(format, devInfo, extension, _
encoding, mimeType, warnings, streamIDs)
execInfo = rs.GetExecutionInfo()
Console.WriteLine("Execution date and time: {0}", execInfo.ExecutionDateTime)
Catch e As SoapException
Console.WriteLine(e.Detail.OuterXml)
End Try
' Write the contents of the report to an MHTML file.
Try
Dim stream As FileStream = 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 e As Exception
Console.WriteLine(e.Message)
End Try
End Sub 'Main
End Class
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);
}
}
}
備註
下表顯示此操作的標頭與權限資訊。
| SOAP 標頭的使用 | (在) TrustedUserHeaderValue (在) ExecutionHeaderValue (出局) ServerInfoHeaderValue |
| 原生模式所需權限 | 關於主報告及所有子報告: ReadProperties 以及 ExecuteAndView |
| SharePoint 模式 必要權限 | 關於主報告及所有子報告: <xref:Microsoft.SharePoint.SPBasePermissions.ViewListItems> |
Render 呈現與標頭中所識別 ExecutionInfo 的報告執行相關的處理中報告。 若執行狀態中處理中的報告不存在暫存快照,此方法將執行該報告(前提是符合所有憑證與參數要求),並建立執行狀態的臨時快照。 若報告因非查詢參數值改變而被重新處理,則會建立新的暫存快照。 欲了解更多執行狀態資訊,請參閱 識別執行狀態。
若執行選項設為快取或執行快照,呼叫 可 Render 使用現有快照。
若報告設定為快取,且提供的參數值與憑證相符,快照的快取副本可能會被載入,而非實際處理報告。
若憑證與參數要求未達標,此方法將回傳錯誤。
若渲染擴充套件支援指定多個頁面,後續呼叫 可用 Render 來擷取報告的額外頁面。
Render 方法的一個限制是輸出無法串流,因此整個檔案必須在記憶體中。
請參閱 「識別執行狀態 」一節,討論執行生命週期,其中包含載入與呈現報告所需步驟的說明。