如何使用ReportingService2010?

我正在尝试使用报告服务器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给了我以下SoapExceptionexception:

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

有什么我做错了或我应该采取的任何其他方法?

我有同样的问题。 我发现的解决方案如下:您使用了错误的DataSource文件格式 – 如下所示:

     XML http://server/_vti_bin/lists.asmx true    

正确的是:

   XML http://server/_vti_bin/lists.asmx Prompt True  True  

您可以通过从Reporting Server下载DataSource来获取此定义。

这是一种从报表服务器中获取每个项目的XML的方法,从某种意义上说,可以从报表服务器“下载”任何对象(包括“DataSource”)的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数据源,这是我们的定义:

   SQL Data Source=MyDatabaseServer;Initial Catalog=MyDatabase Integrated True  

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

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

Microsoft SQL Server报表设计器无法加载报表定义:XML文档中存在错误(2,2)。validation报表定义是否符合正确的架构。 XML文档中存在错误(2,2)。 (的System.Xml)

  was not expected. (wp6bqrt3) 

我刚刚发现CreateCatalogItem的msdn文档具有误导性。

我试图使用Web服务以纯模式(而不是Sharepoint)部署新报表,并且在遵循Parent参数的指导时出错:

键入:System.String

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

页面上的代码示例显示了以下内容:

 string parent = "http:///Docs/Documents/"; 

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

 string parent = "http:////"; 

我收到以下错误:

 Microsoft.ReportingServices.Diagnostics.Utilities.InvalidItemPathException: The path of the item 'http:////' 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 = "/"; 

我从未尝试过通过目录添加数据源,但我确实知道一种可行的方法。 您需要做的就是创建一个数据源,该数据源与您要发布的报告中引用的数据源同名。 以下是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://" + "/_vti_bin/ReportServer/ReportService2010.asmx"; rs.Credentials = System.Net.CredentialCache.DefaultCredentials; string name = "AdventureWorks.rsds"; string parent = "http:///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); } } 

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

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