添加帮助器方法以访问 Crystal Reports Web 服务

在本节中,将创建一个帮助器方法,它通过Crystal Reports Web 服务访问服务器并生成报表列表。

**注意   **此过程要求您具有已配置为使用 Crystal Reports Web 服务的计算机的访问权限。在继续操作之前,请确保已正确配置您的计算机。有关更多信息,请参见在 Crystal 服务中配置服务器文件

创建帮助器方法以访问 Crystal Reports Web 服务

  1. 打开 Web 或 Windows 窗体。

  2. 从“视图”菜单中,单击“代码”。

  3. 添加三个专用类级变量。

    [Visual Basic]

    Private myServerFileReport As ServerFileReport
    Private myReportManagerRequest As ReportManagerRequest
    Private myServerFileReportManagerProxy As ServerFileReportManagerProxy

    [C#]

    private ServerFileReport serverFileReport;
    private ReportManagerRequest reportManagerRequest;
    private ServerFileReportManagerProxy serverFileReportManagerProxy;

  4. 创建一个返回 ArrayList 的新专用帮助器方法。

    [Visual Basic]

    Protected Function getReports() As ArrayList
    End Function

    [C#]

    protected ArrayList getReports()
    {
    }

  5. 在帮助器方法内部,实例化一个新的 ServerFileReport 实例。

    [Visual Basic]

    myServerFileReport = New ServerFileReport()

    [C#]

    serverFileReport = new ServerFileReport();

  6. ServerFileReport 实例的 ReportPath 属性设置为空字符串。

    [Visual Basic]

    myServerFileReport.ReportPath = ""

    [C#]

    serverFileReport.ReportPath = "";

  7. ServerFileReportWebServiceURL 属性设置为所安装的 Crystal Reports 版本的查看器虚拟目录,请参见查看器虚拟目录

    在此示例代码中,为 Crystal Reports for Visual Studio 2005 配置了查看器的虚拟目录。

    [Visual Basic]

    myServerFileReport.WebServiceUrl = "https://localhost:80/CrystalReportsWebServices2005/serverfilereportservice.asmx"

    [C#]

    serverFileReport.WebServiceUrl = "https://localhost:80/CrystalReportsWebServices2005/serverfilereportservice.asmx";

    **注意   **本教程假定报表服务器是本地计算机,因此,您使用 https://localhost:80/ 作为 Web 服务 URL。要使用不同计算机作为报表服务器,请用报表服务器的地址和端口号替换 https://localhost:80/

  8. 实例化一个新的 ReportManagerRequest 实例。

    [Visual Basic]

    myReportManagerRequest = New ReportManagerRequest()

    [C#]

    reportManagerRequest = new ReportManagerRequest();

  9. serverFileReport 实例的 GetExtraData 方法的结果赋值给 ReportManagerRequest 实例的 ExtraData 属性。这会将 ExtraData 属性设置为 Web 服务 URL。

    [Visual Basic]

    myReportManagerRequest.ExtraData = myServerFileReport.GetExtraData()

    [C#]

    reportManagerRequest.ExtraData = serverFileReport.GetExtraData();

  10. serverFileReport 实例的 ToUri 方法的结果赋值给 ReportManagerRequest 实例的 ParentUri 属性。这将指定服务器计算机上包含要列出的报表的目录。

    [Visual Basic]

    myReportManagerRequest.ParentUri = myServerFileReport.ToUri()

    [C#]

    reportManagerRequest.ParentUri = serverFileReport.ToUri();

  11. 实例化一个新的 ServerFileReportManagerProxy 实例。

    [Visual Basic]

    myServerFileReportManagerProxy = New ServerFileReportManagerProxy()

    [C#]

    serverFileReportManagerProxy = new ServerFileReportManagerProxy();

  12. ServerFileReportManagerProxyUrl 属性设置为所安装的 Crystal Reports 版本的服务器文件报表管理器,请参见查看器虚拟目录

    在此示例代码中,为 Crystal Reports for Visual Studio 2005 配置了查看器的虚拟目录。

    [Visual Basic]

    myServerFileReportManagerProxy.Url = "https://localhost:80/CrystalReportsWebServices2005/serverfilereportmanager.asmx"

    [C#]

    serverFileReportManagerProxy.Url = "https://localhost:80/CrystalReportsWebServices2005/serverfilereportmanager.asmx";

  13. 创建并实例化一个新的 ReportManagerResponse 对象。

    [Visual Basic]

    Dim myReportManagerResponse As ReportManagerResponse = new ReportManagerResponse()

    [C#]

    ReportManagerResponse reportManagerResponse = new ReportManagerResponse();

  14. 调用 serverFileReportManagerProxy 实例的 ListChildObjects() 方法,并将结果分配给 ReportManagerResponse 实例。ListChildObjects 方法将返回一个列表,其中包含位于报表服务器上的文件。

    [Visual Basic]

    myReportManagerResponse = myServerFileReportManagerProxy.ListChildObjects(myReportManagerRequest)

    [C#]

    reportManagerResponse = serverFileReportManagerProxy.ListChildObjects(reportManagerRequest);

  15. 创建并实例化一个新的 ArrayList

    [Visual Basic]

    Dim myRemoteReports As ArrayList = New ArrayList()

    [C#]

    ArrayList remoteReports = new ArrayList();

  16. 下一步,创建 For Each 循环,此循环在reportManagerResponse 的每个元素间循环。

    [Visual Basic]

    For Each myReportUriString As String In myReportManagerResponse.ReportUris

Next

\[C\#\]<pre class="code" IsFakePre="true" xmlns="http://www.w3.org/1999/xhtml">foreach (string reportUriString in reportManagerResponse.ReportUris)

{ }

  1. For Each 循环内部,创建一个新的 serverFileReport 实例。

    [Visual Basic]

    myServerFileReport = New ServerFileReport()

    [C#]

    serverFileReport = new ServerFileReport();

  2. serverFileReport Uri 设置为 reportUriString 值。

    [Visual Basic]

    myServerFileReport = ServerFileReport.FromUri(myReportUriString)

    [C#]

    serverFileReport = ServerFileReport.FromUri(reportUriString);

  3. 仍然在 For Each 循环内部,创建一个 If 条件块,用于验证 ServerFileReportObjectType 属性是否为报表类型。

    **注意   **ListChildObjects 方法将返回目录和报表。在本教程中,您将筛选报表文件的对象列表。

    [Visual Basic]

    If (myServerFileReport.ObjectType = EnumServerFileType.REPORT) Then
    End If

    [C#]

    if (serverFileReport.ObjectType == EnumServerFileType.REPORT)
    {
    }

  4. If 条件块内部,将 reportUriString 实例添加到 remoteReport ArrayList 中。

    [Visual Basic]

    myRemoteReports.Add(myReportUriString)

    [C#]

    remoteReports.Add(reportUriString);

  5. 最后,在 For Each 循环外部,返回 remoteReports ArrayList

    [Visual Basic]

    Return myRemoteReports

    [C#]

    return remoteReports;

  6. 在“文件”菜单上单击“全部保存”。

在下一步中,将编写代码,使用报表列表自动填充“DropDownList”或“ComboBox”控件。

对于网站,继续前进到填充在网站中的 DropDownList 控件

对于 Windows 项目,继续前进到填充在 Windows 项目中的 ComboBox 控件

请参见

教程:填充 Web 服务的报表的下拉列表 | 教程和示例代码

将反馈意见发送给 Business Objects

© 2005 Business Objects SA. All Rights Reserved

Business Objects
http://www.china.businessobjects.com/
や穿狝叭
http://www.china.businessobjects.com/BOindex/support/