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. F开发者_StackOverflow社区or XML in reports, refer to Report Definition Language syntax.
Is there something I'm doing wrong or any other approach I should take?
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.
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)
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);
}
}
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>";
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
精彩评论