Compartir a través de


ReportingService2010.CreateDataDrivenSubscription Método

Creates a data-driven subscription for a specified item. This method applies to the Report item type.

Espacio de nombres:  ReportService2010
Ensamblado:  ReportService2010 (en ReportService2010.dll)

Sintaxis

'Declaración
<SoapDocumentMethodAttribute("https://schemas.microsoft.com/sqlserver/reporting/2010/03/01/ReportServer/CreateDataDrivenSubscription", RequestNamespace := "https://schemas.microsoft.com/sqlserver/reporting/2010/03/01/ReportServer",  _
    ResponseNamespace := "https://schemas.microsoft.com/sqlserver/reporting/2010/03/01/ReportServer",  _
    Use := SoapBindingUse.Literal, ParameterStyle := SoapParameterStyle.Wrapped)> _
<SoapHeaderAttribute("ServerInfoHeaderValue", Direction := SoapHeaderDirection.Out)> _
<SoapHeaderAttribute("TrustedUserHeaderValue")> _
Public Function CreateDataDrivenSubscription ( _
    ItemPath 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 ReportingService2010 
Dim ItemPath 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(ItemPath, _
    ExtensionSettings, DataRetrievalPlan, _
    Description, EventType, MatchData, _
    Parameters)
[SoapDocumentMethodAttribute("https://schemas.microsoft.com/sqlserver/reporting/2010/03/01/ReportServer/CreateDataDrivenSubscription", RequestNamespace = "https://schemas.microsoft.com/sqlserver/reporting/2010/03/01/ReportServer", 
    ResponseNamespace = "https://schemas.microsoft.com/sqlserver/reporting/2010/03/01/ReportServer", 
    Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
[SoapHeaderAttribute("ServerInfoHeaderValue", Direction = SoapHeaderDirection.Out)]
[SoapHeaderAttribute("TrustedUserHeaderValue")]
public string CreateDataDrivenSubscription(
    string ItemPath,
    ExtensionSettings ExtensionSettings,
    DataRetrievalPlan DataRetrievalPlan,
    string Description,
    string EventType,
    string MatchData,
    ParameterValueOrFieldReference[] Parameters
)
[SoapDocumentMethodAttribute(L"https://schemas.microsoft.com/sqlserver/reporting/2010/03/01/ReportServer/CreateDataDrivenSubscription", RequestNamespace = L"https://schemas.microsoft.com/sqlserver/reporting/2010/03/01/ReportServer", 
    ResponseNamespace = L"https://schemas.microsoft.com/sqlserver/reporting/2010/03/01/ReportServer", 
    Use = SoapBindingUse::Literal, ParameterStyle = SoapParameterStyle::Wrapped)]
[SoapHeaderAttribute(L"ServerInfoHeaderValue", Direction = SoapHeaderDirection::Out)]
[SoapHeaderAttribute(L"TrustedUserHeaderValue")]
public:
String^ CreateDataDrivenSubscription(
    String^ ItemPath, 
    ExtensionSettings^ ExtensionSettings, 
    DataRetrievalPlan^ DataRetrievalPlan, 
    String^ Description, 
    String^ EventType, 
    String^ MatchData, 
    array<ParameterValueOrFieldReference^>^ Parameters
)
[<SoapDocumentMethodAttribute("https://schemas.microsoft.com/sqlserver/reporting/2010/03/01/ReportServer/CreateDataDrivenSubscription", RequestNamespace = "https://schemas.microsoft.com/sqlserver/reporting/2010/03/01/ReportServer", 
    ResponseNamespace = "https://schemas.microsoft.com/sqlserver/reporting/2010/03/01/ReportServer", 
    Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)>]
[<SoapHeaderAttribute("ServerInfoHeaderValue", Direction = SoapHeaderDirection.Out)>]
[<SoapHeaderAttribute("TrustedUserHeaderValue")>]
member CreateDataDrivenSubscription : 
        ItemPath:string * 
        ExtensionSettings:ExtensionSettings * 
        DataRetrievalPlan:DataRetrievalPlan * 
        Description:string * 
        EventType:string * 
        MatchData:string * 
        Parameters:ParameterValueOrFieldReference[] -> string
public function CreateDataDrivenSubscription(
    ItemPath : String, 
    ExtensionSettings : ExtensionSettings, 
    DataRetrievalPlan : DataRetrievalPlan, 
    Description : String, 
    EventType : String, 
    MatchData : String, 
    Parameters : ParameterValueOrFieldReference[]
) : String

Parámetros

  • ItemPath
    Tipo: System.String
    The fully qualified URL of the item for which to create a data-driven subscription, including the file name and, in SharePoint mode, the extension.
  • Description
    Tipo: System.String
    A meaningful description that is displayed to users.
  • 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 devuelto

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

Comentarios

The table below shows header and permissions information on this operation.

SOAP Header Usage

(In) TrustedUserHeaderValue

(Out) ServerInfoHeaderValue

Native Mode Required Permissions

ExecuteAndView AND CreateAnySubscription

SharePoint Mode Required Permissions

ViewListItems AND ManageAlerts

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

The ItemPath 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 Configuración de la extensión de entrega de 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 nulles una referencia NULL (Nothing en Visual Basic). (or Nothing in Visual Basic).

Using this method sets the LastExecutedSpecified property of the subscription to false, the Status property of the subscription to new subscription, and all properties of the subscription’s Active object to false. The ModifiedBy and ModifiedDate properties of the item are also updated.

Ejemplos

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

Vea también

Referencia

ReportingService2010 Clase

Espacio de nombres ReportService2010