Share via


レッスン 1 : RDL スキーマ Visual Studio プロジェクトの作成

このチュートリアルでは、簡単なコンソール アプリケーションを作成します。このチュートリアルは、Microsoft Visual Studio 2008 での開発を前提としています。

注意

SQL Server Express with Advanced Services で実行されているレポート サーバー Web サービスにアクセスする場合は、"_SQLExpress" を "ReportServer" パスに追加する必要があります。次に例を示します。

http://myserver/reportserver_sqlexpress/reportservice2010.asmx"

Web サービス プロキシを作成するには

  1. [スタート] メニューの [すべてのプログラム]、[Microsoft Visual Studio]、[Visual Studio Tools][Visual Studio 2008 コマンド プロンプト] の順にクリックします。

  2. 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 ファイルを生成します。このファイルをアプリケーションに追加します。

コンソール アプリケーションを作成するには

  1. [ファイル] メニューの [新規作成] をポイントし、[プロジェクト] をクリックして、[新しいプロジェクト] ダイアログ ボックスを開きます。

  2. [プロジェクトの種類] ペインで、[Visual Basic] ノードまたは [Visual C#] ノードをクリックします。

  3. [コンソール アプリケーション] アイコンをクリックします。

  4. [プロジェクト名] ボックスにプロジェクトの名前を入力します。「SampleRDLSchema」と入力します。

  5. [場所] ボックスにプロジェクトを保存するパスを入力するか、[参照] をクリックしてフォルダーに移動します。

  6. [OK] をクリックします。ソリューション エクスプローラーに、プロジェクトが折りたたまれた状態で表示されます。

  7. [プロジェクト] メニューの [既存項目の追加] をクリックします。

  8. 生成した .cs ファイルまたは .vb ファイルの場所に移動してファイルを選択し、[追加] をクリックします。

    また、Web 参照が動作するように、System.Web.Services 名前空間への参照を追加する必要があります。

  9. [プロジェクト] メニューの [参照の追加] をクリックします。

    [参照の追加] ダイアログ ボックスの [.NET] タブで、[System.Web.Services] を選択し、[OK] をクリックします。

    レポート サーバー Web サービスへの接続方法の詳細については、「Web サービスと .NET Framework を使用したアプリケーションの構築」を参照してください。

  10. ソリューション エクスプローラーで、このプロジェクトのノードを展開します。プロジェクトには、Program.cs (Visual Basic の場合は Module1.vb) という既定の名前のコード ファイルが追加されていることがわかります。

  11. Program.cs (Visual Basic の場合は Module1.vb) ファイルを開き、次のコードに置き換えます。

    次のコードは、読み込み、変更、保存の機能を実装するときに使用するメソッドの一部です。

    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 2: Load a report definition from the report 
                //          catalog
            }
    
            private void UpdateReportDefinition()
            {
                //Lesson 3: Update the report definition using the  
                //          classes generated from the RDL Schema
            }
    
            private void PublishReportDefinition()
            {
                //Lesson 4: 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 2: Load a report definition from the report 
                '          catalog
            End Sub
    
            Private Sub UpdateReportDefinition()
                'Lesson 3: Update the report definition using the 
                '          classes generated from the RDL Schema
            End Sub
    
            Private Sub PublishReportDefinition()
                'Lesson 4: Publish the updated report definition back 
                '          to the report catalog
            End Sub
    
        End Module
    
    End Namespace 
    

次のレッスン

次のレッスンでは、XML スキーマ定義ツール (Xsd.exe) を使用して RDL スキーマからクラスを生成し、プロジェクトに組み込みます。「レッスン 2 : xsd ツールを使用して RDL スキーマからクラスを作成」を参照してください。