设置 Web 服务的 Url 属性
在 Microsoft .NET Framework 应用程序中,任何时候都可以修改应用程序当前指向的报表服务器 Web 服务的基 URL。 为此,只需设置服务对象的“Url”属性。 例如:
Dim rs As New ReportingService2010()
rs.Credentials = System.Net.CredentialCache.DefaultCredentials
rs.Url = "https://<Server Name>/reportserver/ReportService2010.asmx"
ReportingService2010 service = new ReportingService2010();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
rs.Url = "https://<Server Name>/reportserver/ReportService2010.asmx";
以下示例从一个报表服务器检索某一报表定义,然后使用该定义在其他报表服务器上创建一个完全相同的报表:
Imports System
Imports System.Web.Services.Protocols
Class Sample
Public Shared Sub Main()
Dim rs As New ReportingService2010()
rs.Credentials = System.Net.CredentialCache.DefaultCredentials
' Set the base Web service URL of the source server
rs.Url = "https://<Server Name>/reportserver/ReportService2010.asmx"
Dim reportName As String = "/SampleReports/Company Sales"
Dim reportDefinition As Byte() = Nothing
Try
' Get the report definition of a report on a source server
reportDefinition = rs.GetItemDefinition(reportName)
' Set the base Web service URL of the destination server
rs.Url = "https://<Server Name>/reportserver/ReportService2010.asmx"
' Create a copy of the report on the destination server
Dim warnings As Warning() = {}
rs.CreateCatalogItem("Report", "Company Sales Copy", "/", False, reportDefinition, Nothing, warnings)
Catch e As SoapException
Console.WriteLine(e.Detail.InnerXml.ToString())
End Try
End Sub 'Main
End Class 'Sample
using System;
using System.Web.Services.Protocols;
class Sample
{
public static void Main()
{
ReportingService2010 rs = new ReportingService2010();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
// Set the base Web service URL of the source server
rs.Url = "https://<Server Name>/reportserver/reportservice2010.asmx";
string reportName = "/SampleReports/Company Sales";
byte[] reportDefinition = null;
try
{
reportDefinition = rs.GetItemDefinition(reportName);
// Set the base Web service URL of the destination server
rs.Url = "https://<Server Name>/reportserver/ReportService2010.asmx";
// Create a copy of the report on the destination server
Warning[] warnings = {};
rs.CreateCatalogItem("Report", "Company Sales Copy", "/", false, reportDefinition, null, out warnings);
}
catch (SoapException e)
{
Console.WriteLine(e.Detail.InnerXml.ToString());
}
}
}
有关创建初始 Web 服务代理的详细信息,请参阅创建 Web 服务代理。