ReportExecutionService.Render 方法

定义

处理特定报表并以指定格式呈现该报表。

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

一个 XML 字符串,其中包含参数中指定的 Format 呈现扩展插件所需的特定于设备的内容。 DeviceInfo 设置必须作为 DeviceInfo XML 元素的内部元素传递。 有关特定输出格式的设备信息设置的详细信息,请参阅 将设备信息设置传递给呈现扩展插件

Extension
String

[out] 与输出流对应的文件扩展名。

MimeType
String

[out] 呈现的报表的 MIME 类型。

Encoding
String

[out] 报表服务器呈现报表内容时使用的编码。

Warnings
Warning[]

[out] Warning 对象的数组,它描述在报表处理过程中出现的所有警告。

StreamIds
String[]

[out] 流标识符。 这些 ID 传递到 RenderStream(String, String, String, String, String) 方法。 可以使用它们来呈现与给定报告相关联的外部资源(图像等)。

如果使用 IMAGE 呈现扩展插件,则 方法在 中 StreamIds输出空数组。

返回

Byte[]

指定格式的报表的 Byte[] 数组。

示例

若要编译以下代码示例,必须引用 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 标头用法 (In) TrustedUserHeaderValue

(In) ExecutionHeaderValue

(Out) ServerInfoHeaderValue
本机模式所需的权限 在main报表和所有子报表上: ReadProperties ANDExecuteAndView
SharePoint 模式所需权限 在main报表和所有子报表上:<xref:Microsoft.SharePoint.SPBasePermissions.ViewListItems>

Render 呈现与标头中 ExecutionInfo 标识的报表执行关联的已处理报表。 如果执行状态中已处理的报表不存在临时快照,则此方法将在满足所有凭据和参数要求) (执行报表,从而为执行状态创建临时快照。 如果由于非查询参数值更改而重新处理报表,则会创建新的临时快照。 有关执行状态的详细信息,请参阅 标识执行状态

如果执行选项设置为缓存或执行快照,则对 Render 的调用可能会使用现有的快照。

如果将报表设置为缓存,并且提供的参数值和凭据匹配,则可能会加载快照的缓存副本,而不是实际处理报表。

如果不满足凭据和参数要求,此方法将返回错误。

如果呈现扩展插件支持指定多个页面,则后续调用 Render 可用于提取报表的其他页。

Render 方法的一个限制是无法流式传输输出,因此整个文件必须位于内存中。

有关执行生命周期的讨论,请参阅 标识执行状态 ,其中包括加载和呈现报表所需步骤的说明。

适用于