可以通过 Reporting Services SOAP API 访问报表服务器的完整功能。 SOAP API 是一项 Web 服务,因此可以轻松访问,以便为自定义业务应用程序提供企业报告功能。 只需编写调用服务的代码即可访问 Windows 应用程序中的 Web 服务。 使用 Microsoft .NET Framework,可以生成一个代理类,该类公开 Web 服务的属性和方法,并使你能够使用熟悉的基础结构和工具生成基于 Reporting Services 技术构建的业务应用程序。
使用 Windows 窗体集成报表管理功能
与 URL 访问不同,SOAP API 公开通过报表服务器提供的一组完整的管理功能。 这意味着报表管理器的整个管理功能可通过 SOAP 向开发人员提供。 因此,可以使用 Windows 窗体开发完整的管理和管理工具。 例如,在 Windows 应用程序中,你可能希望让用户能够检索报表服务器命名空间的内容。 为此,可以使用 Web 服务 ListChildren 方法列出报表服务器数据库中的所有项,然后使用 Listview、Treeview 或 Combobox 控件向用户显示这些项。 当用户单击窗体上的按钮时,以下 Web 服务代码可用于检索用户的“我的报表”文件夹中可用报表的当前列表:
' Button click event that retrieves a list of reports from
' the My Reports folder and displays them in a combo box
Private Sub listReportsButton_Click(sender As Object, e As System.EventArgs)
' Create a new Web service object and set credentials
' to Windows Authentication
Dim rs As New ReportingService2010()
rs.Credentials = System.Net.CredentialCache.DefaultCredentials
' Return the list of items in My Reports
Dim items As CatalogItem() = rs.ListChildren("/Adventureworks 2008 Sample Reports", False)
Dim ci As CatalogItem
For Each ci In items
' If the item is a report, add it to
' a combo box
If ci.TypeName = "Report" Then
catalogComboBox.Items.Add(ci.Name)
End If
Next ci
End Sub 'listReportsButton_Click
// Button click event that retrieves a list of reports from
// the My Reports folder and displays them in a combo box
private void listReportsButton_Click(object sender, System.EventArgs e)
{
// Create a new Web service object and set credentials
// to Windows Authentication
ReportingService2010 rs = new ReportingService2010();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
// Return the list of items in My Reports
CatalogItem[] items = rs.ListChildren("/Adventureworks 2008 Sample Reports", false);
foreach (CatalogItem ci in items)
{
// If the item is a report, add it to
// a combo box
if (ci.TypeName == "Report")
catalogComboBox.Items.Add(ci.Name);
}
}
在此处,用户可以从组合框中选择报表,并使用 Web 浏览器控件或图像控件预览窗体上的报表。
使用 Windows 窗体启用报表查看和导航
有两种方法可用于将报表集成到 Windows 窗体应用程序中。
可以使用 SOAP API 通过该方法将报表呈现到任何受支持的呈现格式 Render 。 启用报表查看和通过 SOAP 导航有轻微的缺点:
不能通过 URL 访问利用 HTML 查看器附带的报表工具栏的内置功能。
如果呈现为 HTML,则必须使用 RenderStream 该方法将任何图像或资源单独呈现为其他流。
使用 URL 访问通过 SOAP API 呈现报表具有轻微的性能优势。
但是, Render SOAP API 的方法可用于呈现报表,并将它们以编程方式保存到各种输出格式。 这比 URL 访问具有优势,这需要用户交互。 使用 SOAP API Render 方法呈现报表时,可以呈现到任何受支持的输出格式。
还可以使用 Visual Studio 2008 Microsoft随附的可自由分发的 ReportViewer 控件。 借助 ReportViewer 控件,可以轻松地将 Reporting Services 功能嵌入自定义应用程序中。 ReportViewer 控件适用于希望作为应用程序功能集的一部分提供预先创作的报表的开发人员(例如,网站管理应用程序可能包含在公司网站上显示点击流分析的报告)。 在应用程序中嵌入控件提供了简化的替代方法,用于在应用程序部署中包括 Reporting Services 服务器组件。 这些控件提供报表功能,但没有你在 Reporting Services 中找到的其他报表创作、发布或分发和传递支持。
ReportViewer 控件有两个版本,一个用于丰富的 Windows 客户端应用程序,一个用于 ASP.NET 应用程序。 这些控件支持本地处理和远程处理模式。 在本地处理模式下,应用程序提供报表定义和数据集,并触发报表处理。 在远程处理模式下,数据检索和报表处理发生在报表服务器上,控件用于显示和报表导航。 使用此模型可以生成可从桌面扩展到企业的丰富应用程序。
ReportViewer 控件记录在 Visual Studio 联机帮助中。 有关详细信息,请参阅 Visual Studio 产品文档。
另请参阅
使用 Web 服务和 .NET Framework 生成应用程序
将 Reporting Services 集成到应用程序中
在 Web 应用程序中使用 SOAP API