Leçon 1 : création du projet Visual Studio du schéma RDL

Dans ce didacticiel, vous allez créer une application console simple. Il est supposé que vous utilisez Microsoft Visual Studio 2008 pour le développement.

Notes

Lorsque vous accédez au service Web Report Server qui s'exécute sur SQL Server Express with Advanced Services, vous devez ajouter "_SQLExpress" au chemin d'accès "ReportServer". Par exemple :

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

Pour créer le proxy de service Web

  1. Dans le menu Démarrer, sélectionnez Tous les programmes, Microsoft Visual Studio, Visual Studio Tools, puis Invite de commandes de Visual Studio 2008.

  2. Dans la fenêtre d'invite de commandes, exécutez la commande suivante si vous utilisez C# :

    wsdl /language:CS /n:"ReportService2010" http://<Server Name>/reportserver/reportservice2010.asmx?wsdl
    

    Si vous utilisez Visual Basic, exécutez la commande suivante :

    wsdl /language:VB /n:"ReportService2010" http://<Server Name>/reportserver/reportservice2010.asmx?wsdl
    

    Cette commande génère un fichier .cs ou .vb. Vous ajouterez ce fichier à votre application.

Pour créer une application console

  1. Dans le menu Fichier, pointez sur Nouveau, puis cliquez sur Projet pour ouvrir la boîte de dialogue Nouveau projet.

  2. Cliquez sur le nœud Visual Basic ou Visual C# dans le volet Types de projets.

  3. Cliquez sur l'icône Application console.

  4. Dans la zone Nom, tapez le nom de votre projet. Tapez le nom SampleRDLSchema.

  5. Dans la zone Emplacement, entrez le chemin d'accès de l'emplacement où vous voulez enregistrer le projet, ou cliquez sur Parcourir pour rechercher le dossier.

  6. Cliquez sur OK. Une vue réduite de votre projet apparaît dans l'Explorateur de solutions.

  7. Dans le menu Projet, cliquez sur Ajouter un élément existant.

  8. Naviguez jusqu'à l'emplacement où vous avez généré le fichier .cs ou .vb, sélectionnez le fichier, puis cliquez sur Ajouter.

    Vous devrez également ajouter une référence à l'espace de noms System.Web.Services pour que votre référence Web fonctionne.

  9. Dans le menu Projet, cliquez sur Ajouter une référence.

    Dans la boîte de dialogue Ajouter une référence, dans l'onglet .NET, sélectionnez System.Web.Services, puis cliquez sur OK.

    Pour plus d'informations sur la manière de se connecter à un service Web Report Server, consultez Génération d'applications à l'aide du service Web et du .NET Framework.

  10. Dans l'Explorateur de solutions, développez le nœud du projet. Un fichier de code portant le nom par défaut Program.cs (Module1.vb pour Visual Basic) a été ajouté à votre projet.

  11. Ouvrez le fichier Program.cs (Module1.vb pour Visual Basic) et remplacez le code par le suivant :

    Le code suivant fournit les stubs de méthode que nous utiliserons pour implémenter les fonctionnalités de chargement, de mise à jour et d'enregistrement.

    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 
    

Leçon suivante

Dans la prochaine leçon, vous allez utiliser l'outil de définition de schéma XML (Xsd.exe) pour générer des classes à partir du schéma RDL et les inclure dans votre projet. Voir Leçon 2 : génération de classes à partir du schéma RDL à l'aide de l'outil xsd.