ReportingService2010.CreateDataDrivenSubscription 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
为指定的项创建数据驱动订阅。 此方法适用于Report
项类型。
public:
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("http://schemas.microsoft.com/sqlserver/reporting/2010/03/01/ReportServer/CreateDataDrivenSubscription", ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped, RequestNamespace="http://schemas.microsoft.com/sqlserver/reporting/2010/03/01/ReportServer", ResponseNamespace="http://schemas.microsoft.com/sqlserver/reporting/2010/03/01/ReportServer", Use=System.Web.Services.Description.SoapBindingUse.Literal)]
[System.Web.Services.Protocols.SoapHeader("ServerInfoHeaderValue", Direction=System.Web.Services.Protocols.SoapHeaderDirection.Out)]
[System.Web.Services.Protocols.SoapHeader("TrustedUserHeaderValue")]
public string CreateDataDrivenSubscription (string ItemPath, ReportService2010.ExtensionSettings ExtensionSettings, ReportService2010.DataRetrievalPlan DataRetrievalPlan, string Description, string EventType, string MatchData, ReportService2010.ParameterValueOrFieldReference[] Parameters);
[<System.Web.Services.Protocols.SoapDocumentMethod("http://schemas.microsoft.com/sqlserver/reporting/2010/03/01/ReportServer/CreateDataDrivenSubscription", ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped, RequestNamespace="http://schemas.microsoft.com/sqlserver/reporting/2010/03/01/ReportServer", ResponseNamespace="http://schemas.microsoft.com/sqlserver/reporting/2010/03/01/ReportServer", Use=System.Web.Services.Description.SoapBindingUse.Literal)>]
[<System.Web.Services.Protocols.SoapHeader("ServerInfoHeaderValue", Direction=System.Web.Services.Protocols.SoapHeaderDirection.Out)>]
[<System.Web.Services.Protocols.SoapHeader("TrustedUserHeaderValue")>]
member this.CreateDataDrivenSubscription : string * ReportService2010.ExtensionSettings * ReportService2010.DataRetrievalPlan * string * string * string * ReportService2010.ParameterValueOrFieldReference[] -> string
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
参数
- ItemPath
- String
要为其创建数据驱动订阅的项的完全限定 URL,其中包括文件名(在 SharePoint 模式下,还有扩展名)。
- ExtensionSettings
- ExtensionSettings
一个 ExtensionSettings 对象,该对象包含特定于传递扩展插件的设置的列表。
- DataRetrievalPlan
- DataRetrievalPlan
一个 DataRetrievalPlan 对象,该对象提供从传递查询中检索数据时所需的设置。 DataRetrievalPlan 对象包含对 DataSetDefinition 对象和 DataSourceDefinitionOrReference 对象的引用。
- Description
- String
向用户显示的贴切描述。
- EventType
- String
触发数据驱动订阅的事件的类型。 有效值是 TimedSubscription
或 SnapshotUpdated
。
- MatchData
- String
与指定 EventType
参数关联的数据。 此参数由事件使用,用来将数据驱动订阅与已经激发的事件进行匹配。
- Parameters
- ParameterValueOrFieldReference[]
一个 ParameterValueOrFieldReference 对象的数组,该数组包含项的参数列表。
返回
一个String
值,该值包含在报表服务器数据库或 SharePoint 库内唯一标识数据驱动订阅的订阅 ID。
- 属性
示例
若要编译此代码示例,必须引用Reporting Services WSDL 并导入某些命名空间。 有关详细信息,请参阅 编译和运行代码示例。 下面的代码示例使用 CreateDataDrivenSubscription 向报表服务器数据库添加新的数据驱动订阅:
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());
}
}
}
注解
下表显示了有关此操作的标头和权限信息。
SOAP 标头用法 | (In) TrustedUserHeaderValue (Out) ServerInfoHeaderValue |
本机模式所需权限 | ExecuteAndView 和 CreateAnySubscription |
SharePoint 模式所需权限 | <xref:Microsoft.SharePoint.SPBasePermissions.ViewListItems> 和 <xref:Microsoft.SharePoint.SPBasePermissions.ManageAlerts> |
参数的 ItemPath
长度不能超过 260 个字符;否则,将引发 SOAP 异常,错误代码 为 rsItemLengthExceeded。
参数 ItemPath
不能为 null 或空,也不能包含以下保留字符: : ? ; @ & = + $ , \ * > < | . "
。 可以使用 /) (正斜杠字符分隔文件夹的完整路径名称中的项目,但不能在文件夹名称的末尾使用它。
可以使用 GetExtensionSettings 方法检索传递扩展插件所需设置的列表。 必须在 参数中 ExtensionSettings
传递这些必需设置的值。 有关电子邮件传递设置的信息,请参阅Reporting Services传递扩展插件设置。
参数 DataRetrievalPlan
采用 DataRetrievalPlan 对象作为其参数。 对象 DataRetrievalPlan 包含带有传递查询的数据集。 CommandType对于数据驱动订阅,传递查询 (QueryDefinition对象) Text
属性默认设置为 ,无需指定。 如果为 CommandType 属性指定值,则该值必须为 Text
。
在数据集中为传递查询提供或引用的数据源必须具有 CredentialRetrieval 设置为 Store
。
传递扩展插件设置和参数的值可以设置为静态值或字段引用。 为传递扩展插件设置或参数指定字段引用时,设置或参数的值由数据驱动。 具有传递查询的数据集具有一组字段 (Field 对象) ,这些字段映射到传递扩展插件设置 (ExtensionParameter 对象) 和报表参数值 (ParameterValue 对象) 。 传递扩展插件设置和报表参数值中引用的所有字段必须与数据集中的字段相对应。 如果传递查询未返回传递扩展插件设置或参数值中指定的字段,则报表服务器将在处理订阅时引发错误。
参数的值 EventType
必须与为报表服务器配置的事件相对应。 用于创建订阅的两个事件是 TimedSubscription
和 SnapshotUpdated
。 ListEvents使用 方法可返回为报表服务器配置的所有事件的列表。
参数的值 MatchData
取决于事件类型。 如果该事件是事件 TimedSubscription
,则需要对象 ScheduleDefinition 作为 MatchData
参数。 必须先将 ScheduleDefinition 对象序列化为 XML,以便将其作为字符串值传递,并根据计划创建订阅。 XML 结构可能类似于以下示例中的结构:
<ScheduleDefinition>
<WeeklyRecurrence>
<StartDateTime>2003-02-24T09:00:00-08:00</StartDateTime>
<WeeksInterval>1</WeeksInterval>
<DaysOfWeek>
<Monday>True</Monday>
</DaysOfWeek>
</WeeklyRecurrence>
</ScheduleDefinition>
作为 XML 字符串传递的 元素的值 StartDateTime 应对应于日期格式 ISO 8601。 此国际日期和时间标准是扩展格式 CCYY-MM-DDThh:mm:ss+/-Z,其中“CC”表示世纪,“YY”表示年份,“MM”表示月份和“DD”日。 字母“T”是日期和时间分隔符,“hh”、“mm”、“ss”分别表示小时、分钟和秒。 此表示形式可能紧跟“Z”,表示协调世界时 (UTC) 。 为了指示时区(表示为本地时间与协调世界时之间的差),“Z”前面是一个“+”或“-”符号,后跟表示为 hh:mm 的 UTC 的差值。
如果 的计划 TimedSubscription
定义是共享计划,则必须将共享计划的计划 ID 作为 MatchData
参数传递。 计划 ID 作为 String
传递,例如“4608ac1b-fc75-4149-9e15-5a8b5781b843”。 可以通过调用 ListSchedules 方法获取计划 ID。
可以使用 XmlSerializer
类自动将对象类转换为 XML 字符串。 有关 类的详细信息XmlSerializer
,请参阅“System.Xml。Microsoft .NET Framework 文档中的 XmlSerializer 类”。
如果事件是 SnapshotUpdated
订阅,则 的值 MatchData
应 null
(或 Nothing
Visual Basic) 中。
使用此方法将 LastExecutedSpecified 订阅的 属性设置为 false
, Status 将订阅的 属性设置为 new subscription
,并将订阅 Active的 对象的所有属性设置为 false
。 项 ModifiedBy 的 和 ModifiedDate 属性也会更新。