ReportingService2005.CreateSubscription(String, ExtensionSettings, String, String, String, ParameterValue[]) Method

Definition

为 Report Server 数据库中的指定报表创建订阅。Creates a subscription for a specified report in the report server database.

public:
 System::String ^ CreateSubscription(System::String ^ Report, ReportService2005::ExtensionSettings ^ ExtensionSettings, System::String ^ Description, System::String ^ EventType, System::String ^ MatchData, cli::array <ReportService2005::ParameterValue ^> ^ Parameters);
public string CreateSubscription (string Report, ReportService2005.ExtensionSettings ExtensionSettings, string Description, string EventType, string MatchData, ReportService2005.ParameterValue[] Parameters);
member this.CreateSubscription : string * ReportService2005.ExtensionSettings * string * string * string * ReportService2005.ParameterValue[] -> string
Public Function CreateSubscription (Report As String, ExtensionSettings As ExtensionSettings, Description As String, EventType As String, MatchData As String, Parameters As ParameterValue()) As String

Parameters

Report
String

要为其创建订阅的报表的完整路径名。The full path name of the report for which to create a subscription.

ExtensionSettings
ExtensionSettings

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

Description
String

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

EventType
String

触发订阅的事件的类型。The type of event that triggers the subscription. 有效值是 TimedSubscriptionSnapshotUpdatedThe valid values are TimedSubscription or SnapshotUpdated.

MatchData
String

与指定的 事件 类型参数关联的数据。The data that is associated with the specified EventType parameter. 此参数由事件使用,用来将订阅与已经激发的事件进行匹配。This parameter is used by an event to match the subscription with an event that has fired.

Parameters
ParameterValue[]

ParameterValue 对象的数组,它包含用于报表的参数的列表。An array of ParameterValue objects that contains a list of parameters for the report.

Returns

String

一个订阅 ID,用来在报表服务器数据库内唯一标识订阅。A subscription ID, which uniquely identifies the subscription in the report server database.

Examples

若要编译此代码示例,必须引用 Reporting Services 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. 下面的代码示例使用 CreateSubscription 将新订阅添加到 Report Server 数据库:The following code example uses CreateSubscription to add a new 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 desc As String = "Send email to anyone@microsoft.com"  
      Dim eventType As String = "TimedSubscription"  
      Dim scheduleXml As String = "<ScheduleDefinition><StartDateTime>2003-02-24T09:00:00-08:00</StartDateTime><WeeklyRecurrence><WeeksInterval>1</WeeksInterval><DaysOfWeek><Monday>True</Monday></DaysOfWeek></WeeklyRecurrence></ScheduleDefinition>"  

      Dim extensionParams(7) As ParameterValue  

      extensionParams(0) = New ParameterValue()  
      extensionParams(0).Name = "TO"  
      extensionParams(0).Value = "dank@adventure-works.com"  

      extensionParams(1) = New ParameterValue()  
      extensionParams(1).Name = "ReplyTo"  
      extensionParams(1).Value = "reporting@adventure-works.com"  

      extensionParams(2) = New ParameterValue()  
      extensionParams(2).Name = "IncludeReport"  
      extensionParams(2).Value = "True"  

      extensionParams(3) = New ParameterValue()  
      extensionParams(3).Name = "RenderFormat"  
      extensionParams(3).Value = "MHTML"  

      extensionParams(4) = New ParameterValue()  
      extensionParams(4).Name = "Subject"  
      extensionParams(4).Value = "@ReportName was executed at @ExecutionTime"  

      extensionParams(5) = New ParameterValue()  
      extensionParams(5).Name = "Comment"  
      extensionParams(5).Value = "Here is your daily sales report for Michael."  

      extensionParams(6) = New ParameterValue()  
      extensionParams(6).Name = "IncludeLink"  
      extensionParams(6).Value = "True"  

      extensionParams(7) = New ParameterValue()  
      extensionParams(7).Name = "Priority"  
      extensionParams(7).Value = "NORMAL"  

      Dim parameter As New ParameterValue()  
      parameter.Name = "EmpID"  
      parameter.Value = "38"  

      Dim parameters(1) As ParameterValue  
      parameters(0) = parameter  

      Dim matchData As String = scheduleXml  
      Dim extSettings As New ExtensionSettings()  
      extSettings.ParameterValues = extensionParams  
      extSettings.Extension = "Report Server Email"  

      Try  
         rs.CreateSubscription(report, extSettings, desc, eventType, matchData, parameters)  

      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;  

      string report = "/SampleReports/Employee Sales Summary";  
      string desc = "Send email to anyone@microsoft.com";  
      string eventType = "TimedSubscription";  
      string scheduleXml = @"<ScheduleDefinition><StartDateTime>2003-02-24T09:00:00-08:00</StartDateTime><WeeklyRecurrence><WeeksInterval>1</WeeksInterval><DaysOfWeek><Monday>True</Monday></DaysOfWeek></WeeklyRecurrence></ScheduleDefinition>";  

      ParameterValue[] extensionParams = new ParameterValue[8];  

      extensionParams[0] = new ParameterValue();  
      extensionParams[0].Name = "TO";  
      extensionParams[0].Value = "dank@adventure-works.com";  

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

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

      extensionParams[3] = new ParameterValue();  
      extensionParams[3].Name = "RenderFormat";  
      extensionParams[3].Value = "MHTML";  

      extensionParams[4] = new ParameterValue();  
      extensionParams[4].Name = "Subject";  
      extensionParams[4].Value = "@ReportName was executed at @ExecutionTime";  

      extensionParams[5] = new ParameterValue();  
      extensionParams[5].Name = "Comment";  
      extensionParams[5].Value = "Here is your daily sales report for Michael.";  

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

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

      ParameterValue parameter = new ParameterValue();  
      parameter.Name = "EmpID";  
      parameter.Value = "38";  

      ParameterValue[] parameters = new ParameterValue[1];  
      parameters[0] = parameter;  

      string matchData = scheduleXml;  
      ExtensionSettings extSettings = new ExtensionSettings();  
      extSettings.ParameterValues = extensionParams;  
      extSettings.Extension = "Report Server Email";  

      try  
      {  
         rs.CreateSubscription(report, extSettings, desc, eventType, matchData, parameters);  
      }  

      catch (SoapException e)  
      {  
         Console.WriteLine(e.Detail.InnerXml.ToString());  
      }  
   }  
}  

Remarks

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

SOAP 标头SOAP Headers (In) BatchHeaderValue(In) BatchHeaderValue

(Out) ServerInfoHeaderValue(Out) ServerInfoHeaderValue
所需的权限Required Permissions ExecuteAndView 和 (CreateAnySubscriptionCreateSubscription) ExecuteAndView AND (CreateAnySubscription OR CreateSubscription)

您可以使用 GetExtensionSettings 方法检索传递扩展插件所需的设置的列表。You can use the GetExtensionSettings method to retrieve a list of required settings for a delivery extension. 必须在参数中为这些必需的设置传递值 ExtensionSettingsYou 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.

参数的值 EventType 必须对应于为 Report Server 配置的事件。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 方法可返回为 Report Server 配置的所有事件的列表。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. 必须先将对象序列化为 XML,才能将 ScheduleDefinition 其作为字符串值传递,并基于计划创建订阅。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:

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

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-DD-Yyyy-mm-ddthh: MM: ss +/-Z,其中 "CC" 表示世纪,"YY" 表示年份,"MM" 表示年份,"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 的计划定义是共享计划,则必须将共享计划的计划 ID 作为 MatchData 参数传递。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 ListSchedulesThe 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 框架文档中的 "System.Xml.Xml序列化程序类"。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 false Status new subscription ,并将订阅对象的所有属性 Active false 设置为。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. ModifiedBy报表的和 ModifiedDate 属性也会更新。The ModifiedBy and ModifiedDate properties of the report are also updated.

Applies to