共用方式為


在 Windows 應用程式中使用 SOAP API

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

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

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

您可以從該處,讓使用者從下拉式方塊中選取報表,並使用網頁瀏覽器控制件或圖像控制項預覽表單上的報表。

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

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

您可以使用SOAP API,使用 Render 方法將報表轉譯至任何支援的轉譯格式。 啟用報表檢視和流覽 SOAP 有一點缺點:

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

  • 如果您轉譯為 HTML,則必須使用 RenderStream 方法,將任何影像或資源個別轉譯為額外的數據流。

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

不過, 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