Compartir a través de


Establecer la propiedad Url del servicio web

En cualquier momento en las aplicaciones de Microsoft.NET Framework, puede modificar la dirección URL base del servicio web del servidor de informes a la que se dirige la aplicación. Para ello, basta con establecer la propiedad Url del objeto de servicio. Por ejemplo:

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";

El ejemplo siguiente recupera una definición de informe de un servidor de informes y utiliza esa definición para crear un informe idéntico en un servidor de informes diferente:

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()); 
      }
   }
}

Para obtener más información sobre cómo crear el proxy del servicio web inicial, vea Crear el proxy del servicio web.