設定 Web 服務的 URL 屬性
在 Microsoft.NET Framework 應用程式中,您隨時都可以修改目前將應用程式導向的報表伺服器 Web 服務之目標基礎 URL。若要這樣做,請直接設定服務物件的 Url 屬性。例如:
Dim rs As New ReportingService2005()
rs.Credentials = System.Net.CredentialCache.DefaultCredentials
rs.Url = "http://<Server Name>/reportserver/ReportService2005.asmx"
ReportingService service = new ReportingService();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
rs.Url = "http://<Server Name>/reportserver/ReportService2005.asmx";
下列範例會從一個報表伺服器擷取報表定義,並使用該定義在不同的報表伺服器上建立相同的報表:
Imports System
Imports System.Web.Services.Protocols
Class Sample
Public Shared Sub Main()
Dim rs As New ReportingService2005()
rs.Credentials = System.Net.CredentialCache.DefaultCredentials
' Set the base Web service URL of the source server
rs.Url = "http://<Server Name>/reportserver/ReportService2005.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.GetReportDefinition(reportName)
' Set the base Web service URL of the destination server
rs.Url = "http://<Server Name>/reportserver/ReportService2005.asmx"
' Create a copy of the report on the destination server
rs.CreateReport("Company Sales Copy", "/", False, reportDefinition, Nothing)
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()
{
ReportingService2005 rs = new ReportingService2005();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
// Set the base Web service URL of the source server
rs.Url = "http://<Server Name>/reportserver/reportservice2005.asmx";
string reportName = "/SampleReports/Company Sales";
byte[] reportDefinition = null;
try
{
reportDefinition = rs.GetReportDefinition(reportName);
// Set the base Web service URL of the destination server
rs.Url = "http://<Server Name>/reportserver/ReportService2005.asmx";
// Create a copy of the report on the destination server
rs.CreateReport("Company Sales Copy", "/", false, reportDefinition, null);
}
catch (SoapException e)
{
Console.WriteLine(e.Detail.InnerXml.ToString());
}
}
}
如需建立初始 Web 服務 Proxy 的詳細資訊,請參閱<建立 Web 服務 Proxy>。