第 1 课:创建 RDL 架构 Visual Studio 项目

在本教程中,你将创建一个简单的控制台应用程序。 本教程假定你在 Visual Studio 2010 Microsoft进行开发。

注释

使用高级服务访问 SQL Server Express 上运行的报表服务器 Web 服务时,必须将“_SQLExpress”追加到“ReportServer”路径。 例如:

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

创建 Web 服务代理

  1. 从“ 开始 ”菜单中,依次选择“ 所有程序”、“Microsoft Visual Studio 工具”和 “Visual Studio 2010 命令提示符”。

  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. 单击 “确定” 。 项目的折叠视图将会出现在解决方案资源管理器中。

  7. 在 项目 菜单上,单击 添加现有项。

  8. 导航到生成的.cs或.vb文件的位置,然后选择该文件,然后单击“ 添加”。

    您还需要为 Services 命名空间添加一个引用,以确保 Web 引用能正常工作。

  9. 在“项目”菜单上,单击“ 添加引用”。

    在 “添加引用 ”对话框中的 “.NET ”选项卡中,选择 System.Web.Services,然后单击“ 确定”。

    有关如何连接到报表服务器 Web 服务的详细信息,请参阅 使用 Web 服务和 .NET Framework 生成应用程序。

  10. 在解决方案资源管理器中,展开项目节点。 你将看到一个代码文件,该文件的默认名称为 Program.cs (Module1.vb for Visual Basic) 已添加到项目中。

  11. 打开 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 架构生成类。

另请参阅

使用从 RDL 架构生成的类更新报表 (SSRS 教程)
报表定义语言 (SSRS)