Método CreateDataDrivenSubscription

Creates a data-driven subscription for a specified report.

Namespace:  ReportService2005
Assembly:  ReportService2005 (em ReportService2005.dll)

Sintaxe

'Declaração
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/sqlserver/2005/06/30/reporting/reportingservices/CreateDataDrivenSubscription", RequestNamespace := "https://schemas.microsoft.com/sqlserver/2005/06/30/reporting/reportingservices",  _
    ResponseNamespace := "https://schemas.microsoft.com/sqlserver/2005/06/30/reporting/reportingservices",  _
    Use := SoapBindingUse.Literal, ParameterStyle := SoapParameterStyle.Wrapped)> _
<SoapHeaderAttribute("BatchHeaderValue")> _
<SoapHeaderAttribute("ServerInfoHeaderValue", Direction := SoapHeaderDirection.Out)> _
Public Function CreateDataDrivenSubscription ( _
    Report As String, _
    ExtensionSettings As ExtensionSettings, _
    DataRetrievalPlan As DataRetrievalPlan, _
    Description As String, _
    EventType As String, _
    MatchData As String, _
    Parameters As ParameterValueOrFieldReference() _
) As String
'Uso
Dim instance As ReportingService2005
Dim Report As String
Dim ExtensionSettings As ExtensionSettings
Dim DataRetrievalPlan As DataRetrievalPlan
Dim Description As String
Dim EventType As String
Dim MatchData As String
Dim Parameters As ParameterValueOrFieldReference()
Dim returnValue As String

returnValue = instance.CreateDataDrivenSubscription(Report, _
    ExtensionSettings, DataRetrievalPlan, _
    Description, EventType, MatchData, _
    Parameters)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/sqlserver/2005/06/30/reporting/reportingservices/CreateDataDrivenSubscription", RequestNamespace = "https://schemas.microsoft.com/sqlserver/2005/06/30/reporting/reportingservices", 
    ResponseNamespace = "https://schemas.microsoft.com/sqlserver/2005/06/30/reporting/reportingservices", 
    Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
[SoapHeaderAttribute("BatchHeaderValue")]
[SoapHeaderAttribute("ServerInfoHeaderValue", Direction = SoapHeaderDirection.Out)]
public string CreateDataDrivenSubscription(
    string Report,
    ExtensionSettings ExtensionSettings,
    DataRetrievalPlan DataRetrievalPlan,
    string Description,
    string EventType,
    string MatchData,
    ParameterValueOrFieldReference[] Parameters
)
[SoapDocumentMethodAttribute(L"https://schemas.microsoft.com/sqlserver/2005/06/30/reporting/reportingservices/CreateDataDrivenSubscription", RequestNamespace = L"https://schemas.microsoft.com/sqlserver/2005/06/30/reporting/reportingservices", 
    ResponseNamespace = L"https://schemas.microsoft.com/sqlserver/2005/06/30/reporting/reportingservices", 
    Use = SoapBindingUse::Literal, ParameterStyle = SoapParameterStyle::Wrapped)]
[SoapHeaderAttribute(L"BatchHeaderValue")]
[SoapHeaderAttribute(L"ServerInfoHeaderValue", Direction = SoapHeaderDirection::Out)]
public:
String^ CreateDataDrivenSubscription(
    String^ Report, 
    ExtensionSettings^ ExtensionSettings, 
    DataRetrievalPlan^ DataRetrievalPlan, 
    String^ Description, 
    String^ EventType, 
    String^ MatchData, 
    array<ParameterValueOrFieldReference^>^ Parameters
)
[<SoapDocumentMethodAttribute("https://schemas.microsoft.com/sqlserver/2005/06/30/reporting/reportingservices/CreateDataDrivenSubscription", RequestNamespace = "https://schemas.microsoft.com/sqlserver/2005/06/30/reporting/reportingservices", 
    ResponseNamespace = "https://schemas.microsoft.com/sqlserver/2005/06/30/reporting/reportingservices", 
    Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)>]
[<SoapHeaderAttribute("BatchHeaderValue")>]
[<SoapHeaderAttribute("ServerInfoHeaderValue", Direction = SoapHeaderDirection.Out)>]
member CreateDataDrivenSubscription : 
        Report:string * 
        ExtensionSettings:ExtensionSettings * 
        DataRetrievalPlan:DataRetrievalPlan * 
        Description:string * 
        EventType:string * 
        MatchData:string * 
        Parameters:ParameterValueOrFieldReference[] -> string 
public function CreateDataDrivenSubscription(
    Report : String, 
    ExtensionSettings : ExtensionSettings, 
    DataRetrievalPlan : DataRetrievalPlan, 
    Description : String, 
    EventType : String, 
    MatchData : String, 
    Parameters : ParameterValueOrFieldReference[]
) : String

Parâmetros

  • Report
    Tipo: System. . :: . .String
    The fully qualified URL of the report for which to create a data-driven subscription.
  • EventType
    Tipo: System. . :: . .String
    The type of event that triggers the data-driven subscription. The valid values are TimedSubscription or SnapshotUpdated.
  • MatchData
    Tipo: System. . :: . .String
    The data that is associated with the specified EventType parameter. This parameter is used by an event to match the data-driven subscription with an event that has fired.

Valor de retorno

Tipo: System. . :: . .String
A String value containing a subscription ID that uniquely identifies the data-driven subscription in the report server database.

Comentários

The length of the Report parameter cannot exceed 260 characters; otherwise, a SOAP exception is thrown with the error code rsItemLengthExceeded.

The Report 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.

You can use the GetExtensionSettings method to retrieve a list of the required settings for a delivery extension. You must pass values for these required settings in the ExtensionSettings parameter. For information about e-mail delivery settings, see Configurações da extensão de entrega do Reporting Services.

The DataRetrievalPlan parameter takes a DataRetrievalPlan object as its argument. The DataRetrievalPlan object contains a dataset with a delivery query. The CommandType property of the delivery query (QueryDefinition object) is set to Text by default for data-driven subscriptions and does not have to be specified. If you specify a value for the CommandType property, the value must be Text.

The data source provided or referenced in the dataset for the delivery query must have a CredentialRetrieval setting of Store.

Values for delivery extension settings and parameters can be set to either static values or to field references. When a field reference is specified for delivery extension setting or a parameter, the value of the setting or parameter is data driven. The dataset with the delivery query has a set of fields (Field objects) that are mapped to delivery extension settings (ExtensionParameter objects) and report parameter values (ParameterValue objects). All fields referenced in delivery extension settings and report parameter values must correspond to the fields in the dataset. If the delivery query does not return a field that is specified in a delivery extension setting or a parameter value, the report server raises an error when the subscription is processed.

The value of the EventType parameter must correspond to an event that is configured for the report server. The two events that are used to create subscriptions are TimedSubscription and SnapshotUpdated. Use the ListEvents method to return a list of all events configured for the report server.

The value of the MatchData parameter depends on the event type. If the event is a TimedSubscription event, a ScheduleDefinition object is required as the MatchData parameter. You must first serialize the ScheduleDefinition object as XML in order to pass it as a string value and create a subscription based on the schedule. The XML structure might look like the one in the following example:

<ScheduleDefinition>
   <WeeklyRecurrence>
      <StartDateTime>2003-02-24T09:00:00-08:00</StartDateTime>
      <WeeksInterval>1</WeeksInterval>
      <DaysOfWeek>
         <Monday>True</Monday>
         </DaysOfWeek>
   </WeeklyRecurrence>
</ScheduleDefinition>

The value of the StartDateTime element when passed as an XML string should correspond to the date format ISO 8601. This international date and time standard is the extended format CCYY-MM-DDThh:mm:ss+/-Z where "CC" represents the century, "YY" the year, "MM" the month and "DD" the day. The letter "T" is the date and time separator and "hh", "mm", "ss" represent hour, minute and second, respectively. This representation may be immediately followed by a "Z" to indicate Coordinated Universal Time (UTC). To indicate the time zone, represented as the difference between the local time and Coordinated Universal Time, "Z" is preceded by a "+" or "-" sign, followed by the difference from UTC represented as hh:mm.

If the schedule definition for a TimedSubscription is a shared schedule, you must pass the schedule ID of the shared schedule as the MatchData parameter. The schedule ID is passed as a String, for example, "4608ac1b-fc75-4149-9e15-5a8b5781b843". The schedule ID can be obtained by calling the ListSchedules method.

You can use the XmlSerializer class to convert your object class to an XML string automatically. For more information about the XmlSerializer class, see "System.Xml.XmlSerializer Class" in the Microsoft .NET Framework documentation.

If the event is a SnapshotUpdated subscription, the value of MatchData should be null Nothing nullptr unit uma referência nula (Nothing no Visual Basic) (or Nothing in Visual Basic).

Using this method sets the LastExecuted property of the subscription to none, the Status property of the subscription to new subscription, and the Active property of the subscription to true. The ModifiedBy and ModifiedDate properties of the report are also updated.

Exemplos

To compile this code example, you must reference the Reporting Services WSDL and import certain namespaces. For more information, see Compiling and Running Code Examples. The following code example uses CreateDataDrivenSubscription to add a new data-driven subscription to the report server database:

Imports System
Imports System.Web.Services.Protocols

Class Sample
   Public Shared Sub Main()
      Dim rs As New ReportingService2005()
      rs.Credentials = System.Net.CredentialCache.DefaultCredentials

      Dim report As String = "/SampleReports/Employee Sales Summary"
      Dim description As String = "My new data driven subscription"

      ' Set the extension setting as report server email.
      Dim settings As New ExtensionSettings()
      settings.Extension = "Report Server Email"

      ' Set the extension parameter values.
      Dim extensionParams(7) As ParameterValueOrFieldReference

      Dim [to] As New ParameterFieldReference() ' Data-driven.
      [to].ParameterName = "TO"
      [to].FieldAlias = "EmailAddress"
      extensionParams(0) = [to]

      Dim replyTo As New ParameterValue()
      replyTo.Name = "ReplyTo"
      replyTo.Value = "dank@adventure-works.com"
      extensionParams(1) = replyTo

      Dim includeReport As New ParameterValue()
      includeReport.Name = "IncludeReport"
      includeReport.Value = "False"
      extensionParams(2) = includeReport

      Dim renderFormat As New ParameterValue()
      renderFormat.Name = "RenderFormat"
      renderFormat.Value = "HTML4.0"
      extensionParams(3) = renderFormat

      Dim priority As New ParameterValue()
      priority.Name = "Priority"
      priority.Value = "NORMAL"
      extensionParams(4) = priority

      Dim subject As New ParameterValue()
      subject.Name = "Subject"
      subject.Value = "Your sales report"
      extensionParams(5) = subject

      Dim comment As New ParameterValue()
      comment.Name = "Comment"
      comment.Value = "Here is the link to your report."
      extensionParams(6) = comment

      Dim includeLink As New ParameterValue()
      includeLink.Name = "IncludeLink"
      includeLink.Value = "True"
      extensionParams(7) = includeLink

      settings.ParameterValues = extensionParams

      ' Create the data source for the delivery query.
      Dim delivery As New DataSource()
      delivery.Name = ""
      Dim dataSourceDefinition As New DataSourceDefinition()
      dataSourceDefinition.ConnectString = "data source=(local);initial catalog=Employee"
      dataSourceDefinition.CredentialRetrieval = CredentialRetrievalEnum.Store
      dataSourceDefinition.Enabled = True
      dataSourceDefinition.EnabledSpecified = True
      dataSourceDefinition.Extension = "SQL"
      dataSourceDefinition.ImpersonateUserSpecified = False
      dataSourceDefinition.UserName = "username"
      dataSourceDefinition.Password = "runUnAtt1"
      delivery.Item = dataSourceDefinition

      ' Create the fields list.
      Dim fieldsList(1) As Field
      fieldsList(0) = New Field()
      fieldsList(0).Name = "EmailAddress"
      fieldsList(0).Alias = "EmailAddress"
      fieldsList(1) = New Field()
      fieldsList(1).Name = "EmpID"
      fieldsList(1).Alias = "EmpID"

      ' Create the data set for the delivery query.
      Dim dataSetDefinition As New DataSetDefinition()
      dataSetDefinition.AccentSensitivitySpecified = False
      dataSetDefinition.CaseSensitivitySpecified = False
      dataSetDefinition.KanatypeSensitivitySpecified = False
      dataSetDefinition.WidthSensitivitySpecified = False
      dataSetDefinition.Fields = fieldsList
      Dim queryDefinition As New QueryDefinition()
      queryDefinition.CommandText = "Select * from MailList"
      queryDefinition.CommandType = "Text"
      queryDefinition.Timeout = 45
      queryDefinition.TimeoutSpecified = True
      dataSetDefinition.Query = queryDefinition
      Dim results As New DataSetDefinition()
      Dim changed As Boolean
      Dim paramNames as String() = Nothing

      Try
         results = rs.PrepareQuery(delivery, dataSetDefinition, changed, paramNames)
      Catch e As SoapException
         Console.WriteLine(e.Detail.InnerText.ToString())
      End Try

      Dim dataRetrieval As New DataRetrievalPlan()
      dataRetrieval.DataSet = results
      dataRetrieval.Item = dataSourceDefinition

      ' Set the event type and match data for the delivery.
      Dim eventType As String = "TimedSubscription"
      Dim matchData As String = "<ScheduleDefinition><StartDateTime>2003-04-14T19:15:00-07:00</StartDateTime><WeeklyRecurrence><WeeksInterval>1</WeeksInterval><DaysOfWeek><Monday>True</Monday><Tuesday>True</Tuesday><Wednesday>True</Wednesday><Thursday>True</Thursday><Friday>True</Friday></DaysOfWeek></WeeklyRecurrence></ScheduleDefinition>"

      ' Set the report parameter values.
      Dim parameters(2) As ParameterValueOrFieldReference

      Dim empID As New ParameterFieldReference() ' Data-driven.
      empID.ParameterName = "EmpID"
      empID.FieldAlias = "EmpID"
      parameters(0) = empID

      Dim reportYear As New ParameterValue()
      reportYear.Name = "ReportYear"
      reportYear.Value = "2004"
      parameters(1) = reportYear

      Dim reportMonth As New ParameterValue()
      reportMonth.Name = "ReportMonth"
      reportMonth.Value = "6" ' June
      parameters(2) = reportMonth

      Try
         Dim subscriptionID As String = rs.CreateDataDrivenSubscription(report, settings, dataRetrieval, description, eventType, matchData, parameters)
      Catch e As SoapException
         Console.WriteLine(e.Detail.InnerText.ToString())
      End Try
   End Sub 'Main
End Class 'Sample
using System;
using System.Web.Services.Protocols;

class Sample
{
   public static void Main()
   {
      ReportingService rs = new ReportingService2005();
      rs.Credentials = System.Net.CredentialCache.DefaultCredentials;

      string report = "/SampleReports/Employee Sales Summary";
      string description = "My new data driven subscription";

      // Set the extension setting as report server email.
      ExtensionSettings settings = new ExtensionSettings();
      settings.Extension = "Report Server Email";

      // Set the extension parameter values.
      ParameterValueOrFieldReference[] extensionParams = 
         new ParameterValueOrFieldReference[8];

      ParameterFieldReference to = new ParameterFieldReference(); // Data-driven.
      to.ParameterName = "TO";
      to.FieldAlias = "EmailAddress"; 
      extensionParams[0] = to;

      ParameterValue replyTo = new ParameterValue();
      replyTo.Name = "ReplyTo";
      replyTo.Value ="dank@adventure-works.com";
      extensionParams[1] = replyTo;

      ParameterValue includeReport = new ParameterValue();
      includeReport.Name = "IncludeReport";
      includeReport.Value = "False";
      extensionParams[2] = includeReport;

      ParameterValue renderFormat = new ParameterValue();
      renderFormat.Name = "RenderFormat";
      renderFormat.Value = "HTML4.0";
      extensionParams[3] = renderFormat;

      ParameterValue priority = new ParameterValue();
      priority.Name = "Priority";
      priority.Value = "NORMAL";
      extensionParams[4] = priority;

      ParameterValue subject = new ParameterValue();
      subject.Name = "Subject";
      subject.Value = "Your sales report";
      extensionParams[5] = subject;

      ParameterValue comment = new ParameterValue();
      comment.Name = "Comment";
      comment.Value = "Here is the link to your report.";
      extensionParams[6] = comment;

      ParameterValue includeLink = new ParameterValue();
      includeLink.Name = "IncludeLink";
      includeLink.Value = "True";
      extensionParams[7] = includeLink;

      settings.ParameterValues = extensionParams;

      // Create the data source for the delivery query.
      DataSource delivery = new DataSource();
      delivery.Name = "";
      DataSourceDefinition dataSourceDefinition = new DataSourceDefinition();
      dataSourceDefinition.ConnectString = "data source=(local);initial catalog=Employee";
      dataSourceDefinition.CredentialRetrieval = CredentialRetrievalEnum.Store;
      dataSourceDefinition.Enabled = true;
      dataSourceDefinition.EnabledSpecified = true;
      dataSourceDefinition.Extension = "SQL";
      dataSourceDefinition.ImpersonateUserSpecified = false;
      dataSourceDefinition.UserName = "username";
      dataSourceDefinition.Password = "runUnAtt1";
      delivery.Item = dataSourceDefinition;

      // Create the fields list.
      Field[] fieldsList = new Field[2];
      fieldsList[0] = new Field();
      fieldsList[0].Name = "EmailAddress";
      fieldsList[0].Alias = "EmailAddress";
      fieldsList[1] = new Field();
      fieldsList[1].Name = "EmpID";
      fieldsList[1].Alias = "EmpID";

      // Create the data set for the delivery query.
      DataSetDefinition dataSetDefinition = new DataSetDefinition();
      dataSetDefinition.AccentSensitivitySpecified = false;
      dataSetDefinition.CaseSensitivitySpecified = false;
      dataSetDefinition.KanatypeSensitivitySpecified = false;
      dataSetDefinition.WidthSensitivitySpecified = false;
      dataSetDefinition.Fields = fieldsList;
      QueryDefinition queryDefinition = new QueryDefinition();
      queryDefinition.CommandText = "Select * from MailList";
      queryDefinition.CommandType = "Text";
      queryDefinition.Timeout = 45;
      queryDefinition.TimeoutSpecified = true;
      dataSetDefinition.Query = queryDefinition;
      DataSetDefinition results = new DataSetDefinition();
      bool changed;
      string[] paramNames;

      try
      {
         results = rs.PrepareQuery(delivery, dataSetDefinition, out changed, out paramNames);
      }
      catch (SoapException e)
      {
         Console.WriteLine(e.Detail.InnerText.ToString());
      }

      DataRetrievalPlan dataRetrieval = new DataRetrievalPlan();
      dataRetrieval.DataSet = results;
      dataRetrieval.Item = dataSourceDefinition;
      // Set the event type and match data for the delivery.
      string eventType = "TimedSubscription";
      string matchData = "<ScheduleDefinition><StartDateTime>2003-04-14T19:15:00-07:00</StartDateTime><WeeklyRecurrence><WeeksInterval>1</WeeksInterval><DaysOfWeek><Monday>True</Monday><Tuesday>True</Tuesday><Wednesday>True</Wednesday><Thursday>True</Thursday><Friday>True</Friday></DaysOfWeek></WeeklyRecurrence></ScheduleDefinition>";

      // Set the report parameter values.
      ParameterValueOrFieldReference[] parameters = new ParameterValueOrFieldReference[3];

      ParameterFieldReference empID = new ParameterFieldReference(); // Data-driven.
      empID.ParameterName = "EmpID";
      empID.FieldAlias = "EmpID";
      parameters[0] = empID;

      ParameterValue reportYear = new ParameterValue();
      reportYear.Name = "ReportYear";
      reportYear.Value = "2004";
      parameters[1] = reportYear;

      ParameterValue reportMonth = new ParameterValue();
      reportMonth.Name = "ReportMonth";
      reportMonth.Value = "6"; // June
      parameters[2] = reportMonth;

      try
      {
         string subscriptionID = rs.CreateDataDrivenSubscription( 
   report, settings, dataRetrieval, description, eventType, matchData, parameters);
      }
      catch (SoapException e)
      {
         Console.WriteLine(e.Detail.InnerText.ToString());
      }
   }
}