分享方式:


使用SOAP整合 Reporting Services - Windows 應用程式

您可以透過 Reporting Services SOAP API 存取報表伺服器的完整功能。 SOAP API 是一種 Web 服務,因此可以輕易地存取,以提供企業報表功能給自訂商務應用程式。 您只要撰寫呼叫服務的程式碼,即可在 Windows 應用程式中存取 Web 服務。 藉由使用 Microsoft .NET Framework,您可以產生 Proxy 類別來公開 Web 服務的屬性和方法。 然後,您可以使用熟悉的基礎結構和工具來建置以 Reporting Services 技術為基礎的商務應用程式。

使用 Windows Forms 整合報表管理功能

與 URL 存取不同的是,SOAP API 會公開一組透過報表伺服器取得的完整管理功能。 這表示報表管理員的整個系統管理功能,是透過 SOAP 提供給開發人員使用。 因此,您可以使用 Windows Form 開發完整的管理工具。 例如,在 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 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 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);  
   }  
}  

從這裡,您可以讓使用者從下拉式方塊選取報表,並使用網頁瀏覽器控制項或是影像控制項來預覽表單上的報表。

使用 Windows Forms 啟用報表檢視和流覽

將報表整合到 Windows Form 應用程式有兩種方法。

您可以使用 SOAP API 將報表轉譯成任何使用 Render 方法的支援轉譯格式。 透過 SOAP 啟用報表檢視與導覽有些輕微的缺點:

  • 您無法透過 URL 存取,利用 HTML 查看器隨附的報表工具列內建功能。

  • 如果您轉譯為 HTML,必須使用 RenderStream 方法,將任何影像或是資源個別轉譯為其他的資料流。

  • 透過使用SOAP API,使用URL存取來轉譯報表有輕微的效能優勢。

不過,您可以用程式設計方式使用 SOAP API 的 Render 方法來轉譯報表,並將它們儲存為各個輸出格式。 此方法是 URL 存取的優點,需要用戶互動。 當您使用 SOAP API Render 方法轉譯報表時,可以轉譯為任何支援的輸出格式。

您也可以使用 Microsoft Visual Studio 2008 隨附且任意散發的報表檢視器控制項。 報表檢視器控制項可輕鬆地將 Reporting Services 功能內嵌至自訂應用程式。 報表查看器控件適用於想要提供預先設計、完整撰寫報表作為應用程式功能集一部分的開發人員。 例如,網站管理應用程式可能包含在公司網站上顯示點擊串流分析的報告。 將控制項內嵌在應用程式中,是將 Reporting Services 伺服器元件包含在應用程式部署中的簡化替代方案。 控件會提供報表功能,但不含您在 Reporting Services 中找到的額外報表撰寫、發行集或散發和傳遞支援。

報表檢視器控制項有兩個版本,一個用於豐富的 Windows 用戶端應用程式,一個用於 ASP.NET 應用程式。 控制項同時支援本機處理和遠端處理模式。 在本機處理模式中,應用程式提供報表定義和資料集以及觸發程序報表處理。 在遠端處理模式中,資料擷取和報表處理是在報表伺服器上進行,而控制項則是用於顯示和報表導覽。 這個模式可讓您建立豐富的應用程式,其範圍從桌上型到企業型都有。

報表檢視器控制項記載於 Visual Studio 線上說明中。 如需詳細資訊,請參閱 Visual Studio 產品文件。

使用 Web 服務和 .NET Framework 建置應用程式
將 Reporting Services 整合到應用程式
在 Web 應用程式中使用 SOAP API