如何使用ReportingService2010?

发布于 2024-10-27 06:37:36 字数 1160 浏览 2 评论 0原文

我正在尝试使用报告服务器 Web 服务通过代码部署报告服务器解决方案: http://_Server_Name_/ ReportServer/ReportService2010.asmx?wsdl

遗憾的是我在网上找不到任何例子。仅来自 MSDN 的一些模糊信息。

通过 Business Intelligence Development Studio 发布时,它会发布共享数据源,然后发布报表。我正在尝试在 C# 上做类似的事情:

var service = new ReportingService2010();
service.Credentials = new NetworkCredential(username, password, domain);

foreach(var dataSourcePath in GetDataSources()) {
    string name = Path.GetFileNameWithoutExtension(dataSourcePath);
    Byte[] content = GetFileContent(dataSourcePath);
    service.CreateCatalogItem("DataSource", name, parent, true, content, null, out warnings);
}

但是 CreateCatalogItem 给了我以下 SoapException 异常:

输入的 XML 不符合 架构。 XML 语法描述于 API 文档。对于 XML 中 报告,参见报告定义 语言语法。 ---> Microsoft.ReportingServices.Diagnostics.Utilities.InvalidXmlException: 输入的 XML 不符合 架构。 XML 语法描述于 API 文档。对于 XML 中 报告,参见报告定义 语言语法。

我做错了什么或者我应该采取其他方法吗?

I'm trying to deploy a reporting server solution by code using the reporting server web service: http://_Server_Name_/ReportServer/ReportService2010.asmx?wsdl.

Sadly I can't find any examples online. Only some vague information from MSDN.

when publishing through the Business Intelligence Development Studio, it publish the shared data source and then publish the reports. I'm trying to so something similar on C#:

var service = new ReportingService2010();
service.Credentials = new NetworkCredential(username, password, domain);

foreach(var dataSourcePath in GetDataSources()) {
    string name = Path.GetFileNameWithoutExtension(dataSourcePath);
    Byte[] content = GetFileContent(dataSourcePath);
    service.CreateCatalogItem("DataSource", name, parent, true, content, null, out warnings);
}

But the CreateCatalogItem gives me the following SoapException exception:

The input XML does not conform to the
schema. XML grammar is described in
the API documentation. For XML in
reports, refer to Report Definition
Language syntax. --->
Microsoft.ReportingServices.Diagnostics.Utilities.InvalidXmlException:
The input XML does not conform to the
schema. XML grammar is described in
the API documentation. For XML in
reports, refer to Report Definition
Language syntax.

Is there something I'm doing wrong or any other approach I should take?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

最冷一天 2024-11-03 06:37:36

我也有同样的问题。我找到的解决方案如下:
您使用了错误的数据源文件格式 - 像这样:

 <?xml version="1.0" encoding="utf-8"?>
 <RptDataSource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Name="DataSourceXML">
    <ConnectionProperties>
        <Extension>XML</Extension>
        <ConnectString>http://server/_vti_bin/lists.asmx</ConnectString>
        <IntegratedSecurity>true</IntegratedSecurity>
    </ConnectionProperties>
    <DataSourceID></DataSourceID>
</RptDataSource> 

正确的格式是:

<?xml version="1.0" encoding="utf-8"?>
<DataSourceDefinition xmlns="http://schemas.microsoft.com/sqlserver/reporting/2006/03/reportdatasource">
  <Extension>XML</Extension>
  <ConnectString>http://server/_vti_bin/lists.asmx</ConnectString>
  <CredentialRetrieval>Prompt</CredentialRetrieval>
  <WindowsCredentials>True</WindowsCredentials>
  <Prompt></Prompt>
  <Enabled>True</Enabled>
</DataSourceDefinition>

您可以通过从报告服务器下载数据源来获取此定义。

I had the same problem. The solution I found is as follows:
You are using wrong DataSource file format - like this:

 <?xml version="1.0" encoding="utf-8"?>
 <RptDataSource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Name="DataSourceXML">
    <ConnectionProperties>
        <Extension>XML</Extension>
        <ConnectString>http://server/_vti_bin/lists.asmx</ConnectString>
        <IntegratedSecurity>true</IntegratedSecurity>
    </ConnectionProperties>
    <DataSourceID></DataSourceID>
</RptDataSource> 

The right one is:

<?xml version="1.0" encoding="utf-8"?>
<DataSourceDefinition xmlns="http://schemas.microsoft.com/sqlserver/reporting/2006/03/reportdatasource">
  <Extension>XML</Extension>
  <ConnectString>http://server/_vti_bin/lists.asmx</ConnectString>
  <CredentialRetrieval>Prompt</CredentialRetrieval>
  <WindowsCredentials>True</WindowsCredentials>
  <Prompt></Prompt>
  <Enabled>True</Enabled>
</DataSourceDefinition>

You can get this definition by downloading DataSource from your Reporting Server.

榕城若虚 2024-11-03 06:37:36

下面是从报表服务器中获取每个项目的 XML 的方法,从某种意义上说,这是一种从报表服务器“下载”包括“数据源”在内的任何对象的 XML 定义的方法(假设您的报表服务器数据库是 ReportServer):

select *, CONVERT(varchar(max),Content) as ContentText
from 
(
      SELECT 
     ItemID,Name,[Type],TypeDescription 
    , CASE 
      WHEN LEFT(Content,3) = 0xEFBBBF 
        THEN CONVERT(varbinary(max),SUBSTRING(Content,4,LEN(Content))) 
      ELSE 
        Content 
      END AS Content 
    from
    (
      SELECT 
         ItemID,Name,[Type] 
       , CASE Type 
          WHEN 2 THEN 'Report' 
          WHEN 5 THEN 'Data Source' 
          WHEN 7 THEN 'Report Part' 
          WHEN 8 THEN 'Shared Dataset' 
          ELSE 'Other' 
         END AS TypeDescription 
       , CONVERT(varbinary(max),Content) AS Content    
       FROM ReportServer.dbo.Catalog 
       WHERE Type IN (2,5,8)
    ) as ItemContentBinaries
) as ItemContentNoBOM

对于 SQL 数据源,这是我们的定义:

<?xml version="1.0" encoding="utf-8"?>
<DataSourceDefinition xmlns="http://schemas.microsoft.com/sqlserver/reporting/2006/03/reportdatasource">
  <Extension>SQL</Extension>
  <ConnectString>Data Source=MyDatabaseServer;Initial Catalog=MyDatabase</ConnectString>
  <CredentialRetrieval>Integrated</CredentialRetrieval>
  <Enabled>True</Enabled>
</DataSourceDefinition>

需要记住的一件事是,我们无法找到一种方法来更改 .rds 文件并使其与报告 IDE 和自动部署一起使用。我们将 .rptproj 与 Visual Studio 2008 一起使用(Visual Studio 2010 无法与 Sql Server 2008 R2 Reporting Server 项目一起使用)。 Visual Studio 2008 要求数据源文件(*.rds 文件)采用旧架构格式,这不适用于 rs.exe 和 CreateCatalogItem。

如果我们将 .rds 文件转换为适用于 CreateCatalogItem 的格式,则 Sql Server 2008 R2 Reporting Server 项目在尝试打开 .rptproj 时会出现以下错误:

Microsoft SQL Server 报表设计器
报告定义加载失败:XML 文档 (2, 2) 中存在错误。请验证报告定义是否符合正确的架构。
XML 文档 (2, 2) 中存在错误。 (系统.Xml)

<DataSourceDefinition xmlns='http://schemas.microsoft.com/sqlserver/reporting/2006/03/reportdatasource'> was not expected. (wp6bqrt3)

Here's a way to get the XML for each item out of the report server, in a sense a way to "download" the XML definition for any object including a "DataSource" from the Reporting Server (assuming your report server database is ReportServer):

select *, CONVERT(varchar(max),Content) as ContentText
from 
(
      SELECT 
     ItemID,Name,[Type],TypeDescription 
    , CASE 
      WHEN LEFT(Content,3) = 0xEFBBBF 
        THEN CONVERT(varbinary(max),SUBSTRING(Content,4,LEN(Content))) 
      ELSE 
        Content 
      END AS Content 
    from
    (
      SELECT 
         ItemID,Name,[Type] 
       , CASE Type 
          WHEN 2 THEN 'Report' 
          WHEN 5 THEN 'Data Source' 
          WHEN 7 THEN 'Report Part' 
          WHEN 8 THEN 'Shared Dataset' 
          ELSE 'Other' 
         END AS TypeDescription 
       , CONVERT(varbinary(max),Content) AS Content    
       FROM ReportServer.dbo.Catalog 
       WHERE Type IN (2,5,8)
    ) as ItemContentBinaries
) as ItemContentNoBOM

For an SQL data source this is the definition we had:

<?xml version="1.0" encoding="utf-8"?>
<DataSourceDefinition xmlns="http://schemas.microsoft.com/sqlserver/reporting/2006/03/reportdatasource">
  <Extension>SQL</Extension>
  <ConnectString>Data Source=MyDatabaseServer;Initial Catalog=MyDatabase</ConnectString>
  <CredentialRetrieval>Integrated</CredentialRetrieval>
  <Enabled>True</Enabled>
</DataSourceDefinition>

One thing to keep in mind is that we could not find a way to change the .rds files and get it to work with both the reporting IDE and automatic deployment. We are using a .rptproj with Visual Studio 2008 (Visual Studio 2010 can't work with Sql Server 2008 R2 Reporting Server projects). Visual Studio 2008 requires the DataSource files (*.rds files) to be in the old schema format, which won't work with rs.exe and CreateCatalogItem.

If we convert the .rds file to a format that works with CreateCatalogItem, the Sql Server 2008 R2 Reporting Server project gives the following error when trying to open the .rptproj:

Microsoft SQL Server Report Designer
The report definition failed to load: There is an error in XML document (2, 2).. Verify the report definition conforms to the correct schema.
There is an error in XML document (2, 2). (System.Xml)

<DataSourceDefinition xmlns='http://schemas.microsoft.com/sqlserver/reporting/2006/03/reportdatasource'> was not expected. (wp6bqrt3)
合久必婚 2024-11-03 06:37:36

我从未真正尝试过通过目录添加数据源,但我确实知道一种肯定有效的方法。
您所需要做的就是创建一个与您要发布的报表中引用的数据源同名的数据源。
以下是来自 MSDN 的使用 ReportingService2010 的示例:

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

class Sample
{
static void Main(string[] args)
{
    ReportingService2010 rs = new ReportingService2010();
    rs.Url = "http://<Server Name>" + 
        "/_vti_bin/ReportServer/ReportService2010.asmx";
    rs.Credentials = 
        System.Net.CredentialCache.DefaultCredentials;

    string name = "AdventureWorks.rsds";
    string parent = "http://<Server Name>/Docs/Documents/";

    // Define the data source definition.
    DataSourceDefinition definition = new DataSourceDefinition();
    definition.CredentialRetrieval = 
        CredentialRetrievalEnum.Integrated;
    definition.ConnectString = 
        "data source=(local);initial catalog=AdventureWorks";
    definition.Enabled = true;
    definition.EnabledSpecified = true;
    definition.Extension = "SQL";
    definition.ImpersonateUserSpecified = false;
    //Use the default prompt string.
    definition.Prompt = null;
    definition.WindowsCredentials = false;

    try
    {
        rs.CreateDataSource(name, parent, false, 
            definition, null);
    }
    catch (SoapException e)
    {
        Console.WriteLine(e.Detail.InnerXml.ToString());
    }
}
}

下面是发布报告并创建数据源的代码,虽然不是为 Reportingservice2010 编写的,但将其移至 2010 应该不难:

Byte[] definition = null;
Warning[] warnings = null;
string parentFolder = "AdventureWorks Sample Reports";
string parentPath = "/" + parentFolder;
string filePath = "D:\\Program Files\\Microsoft SQL Server\\100\\Samples\\Reporting Services\\Report Samples\\AdventureWorks Sample Reports\\";
public void Main()
{
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

//Create the parent folder
try {
    rs.CreateFolder(parentFolder, "/", null);
    Console.WriteLine("Parent folder {0} created successfully", parentFolder);
} catch (Exception e) {
    Console.WriteLine(e.Message);
}

//Publish the sample reports
PublishReport("EmbeddedDatasource");
}

public void PublishReport(string reportName)
{
try {
    FileStream stream = File.OpenRead(filePath + reportName + ".rdl");
    definition = new Byte[stream.Length + 1];
    stream.Read(definition, 0, Convert.ToInt32(stream.Length));
    stream.Close();
} catch (IOException e) {
    Console.WriteLine(e.Message);
}
try {
    warnings = rs.CreateReport(reportName, parentPath, false, definition, null);
    if ((warnings != null)) {
        Warning warning = default(Warning);
        foreach ( warning in warnings) {
            Console.WriteLine(warning.Message);
        }
    } else {
        Console.WriteLine("Report: {0} published successfully with no warnings", reportName);
    }
} catch (Exception e) {
    Console.WriteLine(e.Message);
}
try {
    DataSourceDefinition definition = new DataSourceDefinition();
    definition.CredentialRetrieval = CredentialRetrievalEnum.Store;
    DataSourceReference reference = new DataSourceReference();

    definition.ConnectString = "Data Source=.;Initial Catalog=AdventureWorks";
    definition.UserName = "username";
    definition.Password = "password";
    definition.Extension = "SQL";
    definition.WindowsCredentials = true;
    DataSource[] sources = new DataSource[1];
    DataSource s = new DataSource();
    s.Item = definition;
    s.Name = "DataSource1";
    sources(0) = s;
    rs.SetItemDataSources("/AdventureWorks Sample Reports/EmbeddedDatasource", sources);

} catch (Exception exp) {
    Console.WriteLine(exp.Message);
}
}

I've never actually tried adding a DataSource through the Catalog, but I do know a way that works for sure.
All you need to do is create a datasource that is the same name as the datasource referenced in the report you are publishing.
Here is an example from MSDN using ReportingService2010:

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

class Sample
{
static void Main(string[] args)
{
    ReportingService2010 rs = new ReportingService2010();
    rs.Url = "http://<Server Name>" + 
        "/_vti_bin/ReportServer/ReportService2010.asmx";
    rs.Credentials = 
        System.Net.CredentialCache.DefaultCredentials;

    string name = "AdventureWorks.rsds";
    string parent = "http://<Server Name>/Docs/Documents/";

    // Define the data source definition.
    DataSourceDefinition definition = new DataSourceDefinition();
    definition.CredentialRetrieval = 
        CredentialRetrievalEnum.Integrated;
    definition.ConnectString = 
        "data source=(local);initial catalog=AdventureWorks";
    definition.Enabled = true;
    definition.EnabledSpecified = true;
    definition.Extension = "SQL";
    definition.ImpersonateUserSpecified = false;
    //Use the default prompt string.
    definition.Prompt = null;
    definition.WindowsCredentials = false;

    try
    {
        rs.CreateDataSource(name, parent, false, 
            definition, null);
    }
    catch (SoapException e)
    {
        Console.WriteLine(e.Detail.InnerXml.ToString());
    }
}
}

Here is the code to publish a report and create a datasource, although not written for Reportingservice2010, it shouldn't be to hard to move it over to 2010:

Byte[] definition = null;
Warning[] warnings = null;
string parentFolder = "AdventureWorks Sample Reports";
string parentPath = "/" + parentFolder;
string filePath = "D:\\Program Files\\Microsoft SQL Server\\100\\Samples\\Reporting Services\\Report Samples\\AdventureWorks Sample Reports\\";
public void Main()
{
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

//Create the parent folder
try {
    rs.CreateFolder(parentFolder, "/", null);
    Console.WriteLine("Parent folder {0} created successfully", parentFolder);
} catch (Exception e) {
    Console.WriteLine(e.Message);
}

//Publish the sample reports
PublishReport("EmbeddedDatasource");
}

public void PublishReport(string reportName)
{
try {
    FileStream stream = File.OpenRead(filePath + reportName + ".rdl");
    definition = new Byte[stream.Length + 1];
    stream.Read(definition, 0, Convert.ToInt32(stream.Length));
    stream.Close();
} catch (IOException e) {
    Console.WriteLine(e.Message);
}
try {
    warnings = rs.CreateReport(reportName, parentPath, false, definition, null);
    if ((warnings != null)) {
        Warning warning = default(Warning);
        foreach ( warning in warnings) {
            Console.WriteLine(warning.Message);
        }
    } else {
        Console.WriteLine("Report: {0} published successfully with no warnings", reportName);
    }
} catch (Exception e) {
    Console.WriteLine(e.Message);
}
try {
    DataSourceDefinition definition = new DataSourceDefinition();
    definition.CredentialRetrieval = CredentialRetrievalEnum.Store;
    DataSourceReference reference = new DataSourceReference();

    definition.ConnectString = "Data Source=.;Initial Catalog=AdventureWorks";
    definition.UserName = "username";
    definition.Password = "password";
    definition.Extension = "SQL";
    definition.WindowsCredentials = true;
    DataSource[] sources = new DataSource[1];
    DataSource s = new DataSource();
    s.Item = definition;
    s.Name = "DataSource1";
    sources(0) = s;
    rs.SetItemDataSources("/AdventureWorks Sample Reports/EmbeddedDatasource", sources);

} catch (Exception exp) {
    Console.WriteLine(exp.Message);
}
}
山色无中 2024-11-03 06:37:36

我刚刚发现 CreateCatalogItem 的 msdn 文档 是误导。

我尝试使用 Web 服务以本机模式(不是 Sharepoint)部署新报告,当我按照 Parent 参数的指导进行操作时出现错误:

父级

类型:System.String

将包含该项目的父文件夹的完全限定 URL。

页面上的代码示例显示了这一点:

string parent = "http://<Server Name>/Docs/Documents/";

所以我尝试使用这种格式:

string parent = "http://<Server Name>/<FolderPath>/";

我收到以下错误:

Microsoft.ReportingServices.Diagnostics.Utilities.InvalidItemPathException: 
The path of the item 'http://<Server Name>/<FolderPath>/' is not valid. 
The full path must be less than 260 characters long; other restrictions apply. 
If the report server is in native mode, the path must start with slash.

然后我在注释中注意到这一点(与末尾有斜杠的示例相矛盾):

Parent 参数不能为 null 或为空,也不能包含以下内容
保留字符: : ? ; @& = + $ , \ * > < | 。 “。您可以使用
正斜杠字符 (/) 用于分隔完整路径名中的项目
文件夹,但不能在文件夹名称末尾使用它。

经过反复试验,我最终能够通过将父路径设置为文件夹路径并在开头加上正斜杠来部署报告:

string parent = "/<FolderPath>";

I have just discovered that the msdn documentation for CreateCatalogItem is misleading.

I was trying to deploy a new report in native mode (not Sharepoint) using the webservice, and got an error when I followed the guidance for the Parent parameter:

Parent

Type: System.String

The fully qualified URL for the parent folder that will contain the item.

The code example on the page shows this:

string parent = "http://<Server Name>/Docs/Documents/";

So I tried using this format:

string parent = "http://<Server Name>/<FolderPath>/";

I got the following error:

Microsoft.ReportingServices.Diagnostics.Utilities.InvalidItemPathException: 
The path of the item 'http://<Server Name>/<FolderPath>/' is not valid. 
The full path must be less than 260 characters long; other restrictions apply. 
If the report server is in native mode, the path must start with slash.

Then I noticed this in the remarks (contradicting the example which has a slash at the end):

The Parent parameter cannot be null or empty or contain the following
reserved characters: : ? ; @ & = + $ , \ * > < | . ". You can use the
forward slash character (/) to separate items in the full path name of
the folder, but you cannot use it at the end of the folder name.

After trial and error I was eventually able to deploy the report by setting the parent path to just the folder path, with a forward slash at the start:

string parent = "/<FolderPath>";
故事未完 2024-11-03 06:37:36

只是想提供一些指导。大约一年前,我使用 ReportingService 服务遇到了一些问题,并且在网上发现了很少的信息,所以我从中学到的东西我发布在这里 - 希望这会有所帮助。

http://www.ericwitkowski.com/2013/05 /an-introduction-to-querying-and.html

Just wanted to offer some guidance. I ran through some issues a year ago or so with the ReportingService services and also found little information online, so what I learned from it I posted out here - Hope this helps.

http://www.ericwitkowski.com/2013/05/an-introduction-to-querying-and.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文