在本教學課程中,您將建立簡單的控制台應用程式。 本教學課程假設您在Visual Studio 2010 Microsoft進行開發。
備註
存取在 SQL Server Express 與進階服務上執行的報表伺服器 Web 服務時,您必須將 “_SQLExpress” 附加至 “ReportServer” 路徑。 例如:
http://myserver/reportserver_sqlexpress/reportservice2010.asmx"
建立 Web 服務代理
從 [ 開始] 功能表中,選取 [ 所有程式],然後Microsoft Visual Studio、 Visual Studio Tools,然後選取 [Visual Studio 2010 命令提示字符]。
在命令提示字元視窗中,如果您使用 C#,請執行下列命令:
wsdl /language:CS /n:"ReportService2010" http://<Server Name>/reportserver/reportservice2010.asmx?wsdl如果您使用 Visual Basic,請執行下列命令:
wsdl /language:VB /n:"ReportService2010" http://<Server Name>/reportserver/reportservice2010.asmx?wsdl此命令會產生.cs或.vb檔案。 您將將此檔案新增至您的應用程式。
建立主控台應用程式
在 [ 檔案] 功能表上,指向 [ 新增],然後按兩下 [ 專案 ] 以開啟 [ 新增專案 ] 對話框。
在左窗格中的 [ 已安裝的範本] 底下,按兩下 [Visual Basic ] 或 [ Visual C# ] 節點,然後從展開清單中選取專案類型的類別。
選擇 主控台應用程式 項目類型。
在 [名稱] 方塊中,輸入專案的名稱。 輸入名稱
SampleRDLSchema。在 [ 位置] 方塊中,輸入您要儲存項目的路徑,或按兩下 [ 瀏覽 ] 以瀏覽至資料夾。
按一下 [確定]。 專案的展開視圖會出現在 [方案總管] 中。
在 [專案] 功能表上,按一下 [新增現有項目]。
流覽至您所產生.cs或.vb檔案的位置,然後選取檔案,然後按兩下 [ 新增]。
您還需要新增 Services 命名空間的參考,才能讓您的 Web 參考正常運作。
在 [專案] 功能表上,按兩下 [ 新增參考]。
在 [ 新增參考] 對話框的 [.NET] 索引標籤中,選取 [System.Web.Services],然後按兩下 [ 確定]。
如需如何連線到報表伺服器 Web 服務的詳細資訊,請參閱 使用 Web 服務和 .NET Framework 建置應用程式。
在 [方案總管] 中,展開項目節點。 您會看到已將預設名稱為 Program.cs 的程式代碼檔案 (Module1.vb for Visual Basic) 新增至您的專案。
開啟 Program.cs (Module1.vb for Visual Basic) 檔案,並以下列程式代碼取代程式代碼:
以下的程式碼提供我們用來實作載入、更新和儲存功能的方法雛型。
using System; using System.Collections.Generic; using System.IO; using System.Text; using System.Xml; using System.Xml.Serialization; using ReportService2010; namespace SampleRDLSchema { class ReportUpdater { ReportingService2010 _reportService; static void Main(string[] args) { ReportUpdater reportUpdater = new ReportUpdater(); reportUpdater.UpdateReport(); } private void UpdateReport() { try { // Set up the Report Service connection _reportService = new ReportingService2010(); _reportService.Credentials = System.Net.CredentialCache.DefaultCredentials; _reportService.Url = "http://<Server Name>/reportserver/" + "reportservice2010.asmx"; // Call the methods to update a report definition LoadReportDefinition(); UpdateReportDefinition(); PublishReportDefinition(); } catch (Exception ex) { System.Console.WriteLine(ex.Message); } } private void LoadReportDefinition() { //Lesson 3: Load a report definition from the report // catalog } private void UpdateReportDefinition() { //Lesson 4: Update the report definition using the // classes generated from the RDL Schema } private void PublishReportDefinition() { //Lesson 5: Publish the updated report definition back // to the report catalog } } }Imports System Imports System.Collections.Generic Imports System.IO Imports System.Text Imports System.Xml Imports System.Xml.Serialization Imports ReportService2010 Namespace SampleRDLSchema Module ReportUpdater Private m_reportService As ReportingService2010 Public Sub Main(ByVal args As String()) Try 'Set up the Report Service connection m_reportService = New ReportingService2010 m_reportService.Credentials = _ System.Net.CredentialCache.DefaultCredentials m_reportService.Url = _ "http:// <Server Name>/reportserver/" & _ "reportservice2010.asmx" 'Call the methods to update a report definition LoadReportDefinition() UpdateReportDefinition() PublishReportDefinition() Catch ex As Exception System.Console.WriteLine(ex.Message) End Try End Sub Private Sub LoadReportDefinition() 'Lesson 3: Load a report definition from the report ' catalog End Sub Private Sub UpdateReportDefinition() 'Lesson 4: Update the report definition using the ' classes generated from the RDL Schema End Sub Private Sub PublishReportDefinition() 'Lesson 5: Publish the updated report definition back ' to the report catalog End Sub End Module End Namespace
下一課
在下一課中,您將使用 XML 架構定義工具 (Xsd.exe) 從 RDL 架構產生類別,並將其包含在專案中。 請參閱 第 2 課:使用 xsd 工具從 RDL 架構產生類別。