このチュートリアルでは、単純なコンソール アプリケーションを作成します。 このチュートリアルでは、Microsoft Visual Studio 2010 で開発していることを前提としています。
注
SQL Server Express で実行されているレポート サーバー Web サービスに Advanced Services を使用してアクセスする場合は、"_SQLExpress" を "ReportServer" パスに追加する必要があります。 例えば次が挙げられます。
http://myserver/reportserver_sqlexpress/reportservice2010.asmx"
Web サービス プロキシを作成するには
[スタート] メニューから、[すべてのプログラム]、[Microsoft Visual Studio]、[Visual Studio ツール]、[Visual Studio 2010 コマンド プロンプト] の順に選択します。
C# を使用している場合は、コマンド プロンプト ウィンドウで次のコマンドを実行します。
wsdl /language:CS /n:"ReportService2010" http://<Server Name>/reportserver/reportservice2010.asmx?wsdlVisual Basic を使用している場合は、次のコマンドを実行します。
wsdl /language:VB /n:"ReportService2010" http://<Server Name>/reportserver/reportservice2010.asmx?wsdlこのコマンドは、.csまたは.vbファイルを生成します。 このファイルをアプリケーションに追加します。
コンソール アプリケーションを作成するには
[ ファイル ] メニューの [ 新規作成] をポイントし、[ プロジェクト ] をクリックして [ 新しいプロジェクト ] ダイアログ ボックスを開きます。
左側のウィンドウの [ インストールされているテンプレート] で、 Visual Basic または Visual C# ノードをクリックし、展開された一覧からプロジェクトの種類のカテゴリを選択します。
[コンソール アプリケーション] プロジェクトの種類を選択します。
[プロジェクト名] ボックスにプロジェクトの名前を入力します。
SampleRDLSchema名を入力します。[ 場所 ] ボックスに、プロジェクトを保存するパスを入力するか、[ 参照 ] をクリックしてフォルダーに移動します。
OK をクリックします。 プロジェクトの折りたたまれたビューがソリューション エクスプローラーに表示されます。
[プロジェクト] メニューの [既存 項目の追加]をクリックします。
生成した.csまたは.vbファイルの場所に移動し、ファイルを選択して、[ 追加] をクリックします。
また、Web 参照を機能させるには、 Services 名前空間への参照を追加する必要があります。
[プロジェクト] メニューの [ 参照の追加] をクリックします。
[ 参照の追加 ] ダイアログ ボックスの [.NET ] タブで[ System.Web.Services] を選択し、[OK] をクリック します。
レポート サーバー Web サービスに接続する方法の詳細については、「 Web サービスと .NET Framework を使用したアプリケーションの構築」を参照してください。
ソリューション エクスプローラーで、プロジェクト ノードを展開します。 既定の名前が Program.cs (Visual Basic の場合Module1.vb) のコード ファイルがプロジェクトに追加されていることがわかります。
Program.cs (Visual Basic のModule1.vb) ファイルを開き、コードを次のように置き換えます。
次のコードは、Load、Update、Save 機能の実装に使用するメソッド スタブを提供します。
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 スキーマからクラスを生成する」を参照してください。
こちらもご覧ください
RDL スキーマから生成されたクラスを使用したレポートの更新 (SSRS チュートリアル)
レポート定義言語 (SSRS)