ReportingService2010.CreateDataDrivenSubscription(String, ExtensionSettings, DataRetrievalPlan, String, String, String, ParameterValueOrFieldReference[]) ReportingService2010.CreateDataDrivenSubscription(String, ExtensionSettings, DataRetrievalPlan, String, String, String, ParameterValueOrFieldReference[]) Method


为指定的项创建数据驱动订阅。 Creates a data-driven subscription for a specified item. 此方法适用于Report项目类型。 This method applies to the Report item type.

 System::String ^ CreateDataDrivenSubscription(System::String ^ ItemPath, ReportService2010::ExtensionSettings ^ ExtensionSettings, ReportService2010::DataRetrievalPlan ^ DataRetrievalPlan, System::String ^ Description, System::String ^ EventType, System::String ^ MatchData, cli::array <ReportService2010::ParameterValueOrFieldReference ^> ^ Parameters);
[System.Web.Services.Protocols.SoapDocumentMethod("", ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped, RequestNamespace="", ResponseNamespace="", Use=System.Web.Services.Description.SoapBindingUse.Literal)]
[System.Web.Services.Protocols.SoapHeader("ServerInfoHeaderValue", Direction=System.Web.Services.Protocols.SoapHeaderDirection.Out)]
public string CreateDataDrivenSubscription (string ItemPath, ReportService2010.ExtensionSettings ExtensionSettings, ReportService2010.DataRetrievalPlan DataRetrievalPlan, string Description, string EventType, string MatchData, ReportService2010.ParameterValueOrFieldReference[] Parameters);
String String

要为其创建数据驱动订阅的项的完全限定 URL,其中包括文件名(在 SharePoint 模式下,还有扩展名)。 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.

ExtensionSettings ExtensionSettings

ExtensionSettings对象,其中包含特定于的传递扩展插件的设置的列表。 An ExtensionSettings object that contains a list of settings that are specific to the delivery extension.

DataRetrievalPlan DataRetrievalPlan

ADataRetrievalPlan提供从传递查询检索数据所需的设置的对象。 A DataRetrievalPlan object that provides settings that are required to retrieve data from a delivery query. DataRetrievalPlan对象包含对引用DataSetDefinition对象和一个DataSourceDefinitionOrReference对象。 The DataRetrievalPlan object contains a reference to a DataSetDefinition object and a DataSourceDefinitionOrReference object.

String String

向用户显示的贴切描述。 A meaningful description that is displayed to users.

String String

触发数据驱动订阅的事件的类型。 The type of event that triggers the data-driven subscription. 有效值为TimedSubscriptionSnapshotUpdated The valid values are TimedSubscription or SnapshotUpdated.

String String

与指定的关联的数据EventType参数。 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.


一个 ParameterValueOrFieldReference 对象的数组,该数组包含项的参数列表。 An array of ParameterValueOrFieldReference objects that contains a list of parameters for the item.


AString值,该值包含唯一标识报表服务器数据库或 SharePoint 库中的数据驱动订阅的订阅 ID。 A String value containing a subscription ID that uniquely identifies the data-driven subscription in the report server database or SharePoint library.


若要编译此代码示例,必须引用 Reporting 服务 WSDL,并导入某些命名空间。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. 下面的代码示例使用CreateDataDrivenSubscription将新的数据驱动订阅添加到报表服务器数据库: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 = ""  
      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  

         results = rs.PrepareQuery(delivery, dataSetDefinition, changed, paramNames)  
      Catch e As SoapException  
      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  

         Dim subscriptionID As String = rs.CreateDataDrivenSubscription(report, settings, dataRetrieval, description, eventType, matchData, parameters)  
      Catch e As SoapException  
      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 ="";  
      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;  

         results = rs.PrepareQuery(delivery, dataSetDefinition, out changed, out paramNames);  
      catch (SoapException e)  

      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;  

         string subscriptionID = rs.CreateDataDrivenSubscription(   
   report, settings, dataRetrieval, description, eventType, matchData, parameters);  
      catch (SoapException e)  


下表显示了有关此操作的标头和权限信息。The table below shows header and permissions information on this operation.

SOAP 标头使用情况SOAP Header Usage (In) TrustedUserHeaderValue(In) TrustedUserHeaderValue

(Out) ServerInfoHeaderValue(Out) ServerInfoHeaderValue
纯模式所需的权限Native Mode Required Permissions ExecuteAndViewCreateAnySubscriptionExecuteAndView AND CreateAnySubscription
SharePoint 模式所需的权限SharePoint Mode Required Permissions ViewListItemsManageAlertsViewListItems AND ManageAlerts

长度ItemPath参数不能超过 260 个字符; 否则,将 SOAP 异常引发,错误代码rsItemLengthExceededThe length of the ItemPath parameter cannot exceed 260 characters; otherwise, a SOAP exception is thrown with the error code rsItemLengthExceeded.

ItemPath参数不能为 null 或为空或包含下列保留的字符: : ? ; @ & = + $ , \ * > < | . "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.

你可以使用GetExtensionSettings方法来检索其中的传递扩展插件的必需设置的列表。You can use the GetExtensionSettings method to retrieve a list of the required settings for a delivery extension. 您必须将值传递为这些所需中ExtensionSettings参数。You must pass values for these required settings in the ExtensionSettings parameter. 有关电子邮件传递设置的信息,请参阅Reporting Services 传递扩展插件设置For information about e-mail delivery settings, see Reporting Services Delivery Extension Settings.

DataRetrievalPlan参数采用DataRetrievalPlan对象作为其参数。The DataRetrievalPlan parameter takes a DataRetrievalPlan object as its argument. DataRetrievalPlan对象包含具有传递查询的数据集。The DataRetrievalPlan object contains a dataset with a delivery query. CommandType传递查询的属性 (QueryDefinition对象) 设置为Text默认情况下,为数据驱动订阅,而未指定。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. 如果指定的值CommandType属性,值必须为TextIf you specify a value for the CommandType property, the value must be Text.

数据源提供或引用数据集中传递查询必须具有CredentialRetrieval设置StoreThe 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. 使用传递查询数据集具有一组字段 (Field对象),映射到传递扩展插件设置 (ExtensionParameter对象) 和报表参数值 (ParameterValue对象)。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.

EventType参数必须对应于为报表服务器配置的事件。The value of the EventType parameter must correspond to an event that is configured for the report server. 用于创建订阅的两个事件都TimedSubscriptionSnapshotUpdatedThe two events that are used to create subscriptions are TimedSubscription and SnapshotUpdated. 使用ListEvents方法以返回为报表服务器配置的所有事件的列表。Use the ListEvents method to return a list of all events configured for the report server.

MatchData参数取决于事件类型。The value of the MatchData parameter depends on the event type. 如果事件是TimedSubscription事件, ScheduleDefinition ,则需要为对象MatchData参数。If the event is a TimedSubscription event, a ScheduleDefinition object is required as the MatchData parameter. 你必须先序列化为ScheduleDefinition对象以将其作为一个字符串值传递和创建订阅的 XML 作为基于的计划。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. XML 结构可能类似于下面的示例中的一个:The XML structure might look like the one in the following example:


StartDateTime元素的 XML 字符串作为传递时应对应的日期格式 ISO 8601。The value of the StartDateTime element when passed as an XML string should correspond to the date format ISO 8601. 这国际日期和时间标准是扩展的格式 CCYY-MM-DDThh:mm:ss + /-其中"CC"表示世纪,"YY"年份"MM"月份的 Z 和"DD"一天。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. 字母"T"的日期和时间分隔符和"hh","mm","ss"分别表示小时、 分钟和秒。The letter "T" is the date and time separator and "hh", "mm", "ss" represent hour, minute and second, respectively. 此表示形式可能立即跟"Z"指示协调世界时 (UTC)。This representation may be immediately followed by a "Z" to indicate Coordinated Universal Time (UTC). 以指示时区,表示为协调世界时和当地时间之间的差异"Z"前面有"+"或"-"符号后, 跟与 UTC 表示为 hh: mm 的差值。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.

如果为该计划定义TimedSubscription是共享的计划,你必须通过为该共享计划的计划 IDMatchData参数。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. 作为传递 ID 的计划String,例如,"4608ac1b-fc75-4149-9e15-5a8b5781b843"。The schedule ID is passed as a String, for example, "4608ac1b-fc75-4149-9e15-5a8b5781b843". 可以通过调用获取 ID 的计划ListSchedules方法。The schedule ID can be obtained by calling the ListSchedules method.

你可以使用XmlSerializer若要自动转换为 XML 字符串的对象类的类。You can use the XmlSerializer class to convert your object class to an XML string automatically. 有关详细信息XmlSerializer类中,请参阅 Microsoft.NET Framework 文档中的"System.Xml.XmlSerializer 类"。For more information about the XmlSerializer class, see "System.Xml.XmlSerializer Class" in the Microsoft .NET Framework documentation.

如果事件是SnapshotUpdated订阅、 的值MatchDatanull(或Nothing在 Visual Basic 中)。If the event is a SnapshotUpdated subscription, the value of MatchData should be null (or Nothing in Visual Basic).

使用此方法会设置LastExecutedSpecified对订阅的属性falseStatus对订阅的属性new subscription,和的订阅的所有属性Active对象传递给falseUsing 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 Activeobject to false. ModifiedByModifiedDate也将更新的项目属性。The ModifiedBy and ModifiedDate properties of the item are also updated.