次の方法で共有


ReportingService2005.CancelJob(String) メソッド

定義

ジョブの実行を取り消します。

public:
 bool CancelJob(System::String ^ JobID);
public bool CancelJob (string JobID);
member this.CancelJob : string -> bool
Public Function CancelJob (JobID As String) As Boolean

パラメーター

JobID
String

取り消すジョブの ID です。 ジョブ ID は、JobID オブジェクトの Job プロパティから取得できます。

戻り値

Boolean 値。 ジョブが正常に取り消されると、値 true が返されます。

このコード例をコンパイルするには、Reporting Services の WSDL を参照し、特定の名前空間をインポートする必要があります。 詳細については、「 コード例のコンパイルと実行」を参照してください。 次のコード例は、指定したレポート サーバー上で実行中のすべてのジョブをキャンセルできるコンソール アプリケーションです。

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 jobs As Job() = Nothing  

      ' Return a list of current jobs.  
      Try  
         jobs = rs.ListJobs()  

         ' Provides a prompt to cancel current jobs.  
         If ListRunningJobs(jobs) Then  
            Console.Write("Do you want to cancel these jobs (Y/N)?")  
            Dim input As Integer = Console.Read()  
            If [Char].ToLower(CChar(input)) = "y"c Then  
               CancelRunningJobs(jobs, rs)  
            End If  
         End If  
      Catch e As SoapException  
         Console.WriteLine(e.Detail.InnerXml.ToString())  
      End Try  
   End Sub 'Main  

   ' Method to send a list of current jobs and their properties  
   ' to standard output.  
   Public Shared Function ListRunningJobs(jobs() As Job) As Boolean  
      Dim runningJobCount As Integer = 0  
      Console.WriteLine("Current Jobs")  
      Console.WriteLine(("================================" + Environment.NewLine))  
      Dim job As Job  
      For Each job In  jobs  
         If job.Status = JobStatusEnum.Running Or job.Status = JobStatusEnum.New Then  
            Console.WriteLine("--------------------------------")  
            Console.WriteLine("JobID: {0}", job.JobID)  
            Console.WriteLine("--------------------------------")  
            Console.WriteLine("Action: {0}", job.Action)  
            Console.WriteLine("Description: {0}", job.Description)  
            Console.WriteLine("Machine: {0}", job.Machine)  
            Console.WriteLine("Name: {0}", job.Name)  
            Console.WriteLine("Path: {0}", job.Path)  
            Console.WriteLine("StartDateTime: {0}", job.StartDateTime)  
            Console.WriteLine("Status: {0}", job.Status)  
            Console.WriteLine("Type: {0}", job.Type)  
            Console.WriteLine("User: {0}" + Environment.NewLine, job.User)  
            runningJobCount += 1  
         End If  
      Next job  
      Console.Write("There are {0} running jobs. ", runningJobCount)  
      If runningJobCount > 0 Then  
         Return True  
      Else  
         Return False  
      End If  
   End Function 'ListRunningJobs  

   Public Shared Sub CancelRunningJobs(jobs() As Job, rs As ReportingService)  
      Try  
         Dim job As Job  
         For Each job In  jobs  
            If job.Status = JobStatusEnum.Running Or job.Status = JobStatusEnum.New Then  
               rs.CancelJob(job.JobID)  
            End If  
         Next job  
         Console.WriteLine("All jobs successfully canceled.")  
      Catch e As SoapException  
         Console.WriteLine(e.Detail.InnerXml.ToString())  
      End Try  
   End Sub 'CancelRunningJobs  
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;  

      Job[] jobs = null;  

      // Return a list of current jobs.  
      try  
      {  
         jobs = rs.ListJobs();  

         // Provides a prompt to cancel current jobs.  
         if (ListRunningJobs(jobs))  
         {  
            Console.Write("Do you want to cancel these jobs (Y/N)?");  
            int input = Console.Read();  
            if (Char.ToLower((char)input)== 'y')   
            {  
               CancelRunningJobs(jobs, rs);  
            }  
         }  
      }  
      catch (SoapException e)  
      {  
         Console.WriteLine(e.Detail.InnerXml.ToString());  
      }  
   }  

   // Method to send a list of current jobs and their properties  
   // to standard output.  
   public static bool ListRunningJobs(Job[] jobs)  
   {     
      int runningJobCount = 0;  
      Console.WriteLine("Current Jobs");  
      Console.WriteLine("================================" + Environment.NewLine);  
      foreach (Job job in jobs)  
      {  
         if (job.Status == JobStatusEnum.Running ||   
               job.Status == JobStatusEnum.New)  
         {     
            Console.WriteLine("--------------------------------");  
            Console.WriteLine("JobID: {0}", job.JobID);  
            Console.WriteLine("--------------------------------");  
            Console.WriteLine("Action: {0}", job.Action);  
            Console.WriteLine("Description: {0}", job.Description);  
            Console.WriteLine("Machine: {0}", job.Machine);  
            Console.WriteLine("Name: {0}", job.Name);  
            Console.WriteLine("Path: {0}", job.Path);  
            Console.WriteLine("StartDateTime: {0}", job.StartDateTime);  
            Console.WriteLine("Status: {0}", job.Status);  
            Console.WriteLine("Type: {0}", job.Type);  
            Console.WriteLine("User: {0}" + Environment.NewLine, job.User);  
            runningJobCount++;  
         }  
      }  
      Console.Write("There are {0} running jobs. ", runningJobCount);  
      if (runningJobCount > 0)  
         return true;  
      else  
         return false;  
   }  

   public static void CancelRunningJobs(Job[] jobs, ReportingService rs)  
   {     
      try  
      {  
         foreach (Job job in jobs)  
         {  
            if (job.Status == JobStatusEnum.Running ||   
               job.Status == JobStatusEnum.New)  
            {     
               rs.CancelJob(job.JobID);  
            }  
         }  
         Console.WriteLine("All jobs successfully canceled.");  
      }  
      catch (SoapException e)  
      {  
         Console.WriteLine(e.Detail.InnerXml.ToString());  
      }  
   }  
}  

注釈

次の表に、この操作に関連するヘッダーおよび権限の情報を示します。

SOAP ヘッダー (Out) ServerInfoHeaderValue
必要なアクセス許可 CancelJobs

JobID パラメーターで渡したジョブ ID が見つからない場合は、エラーが返されます。 既に取り消されているジョブ ID を使用してこのメソッドを呼び出すと、レポート サーバーによって操作が無視されます。

レポート サーバーで現在実行されているジョブの一覧を取得するには、ListJobs メソッドを使用します。

適用対象