トップページへ PASSJ ブログへ
トップページへ
分科会
特集!
コミュニケーション
資格
セミナー・コンファレンス
インフォメーション



Webテクノロジー ボードリーダー:小川 貢

毎月第2、第4木曜日はボードリーダーからのレポートを掲載いたします。
 
   

2004年6月10日
『どっとねっとと雑多な日々 29』

むちゃくちゃのスケジュールで推し進めていたプロジェクトが、お客様の都合により 2 ヶ月も延期になり、やっと人並みの生活が送れそうな気配が感じられます。
おかげさまで、PASSJ 合宿 in 熱海に参加できることになりました。

PASSJ 合宿で SQL Server 2000 Reporting Services についてセミナーがありますが、一足先に私もネタを書きましょう。

「どっとねっとと雑多な日々 26」で、SQL Server 2000 Reporting Services を Visual Studio .NET から操作する場合は SOAP でという話を書きました。SQL Server 2000 Reporting Services のサンプル RSExplorer を見ればわかるのですが、実はもっと簡単に実装できるのです。

基本は XML Web Service を利用することには変わりないのですが、Visual Studio .NET から「Web 参照」の追加を行うことで簡単に開発ができます。

SQL Server 2000 Reporting Services の XML Web Service は

http://localhost/ReportServer/ReportService.asmx

になります。
※ localhost は SQL Server 2000 Reporting Services をインストールしたマシン名を指定して
ください。

追加した Web 参照を元に SQL Server 2000 Reporting Services に展開されている Report の名前を列挙するサンプルコードを書きましたので参考にしてください。
※肝は「getReportList_Click」イベントです。

--
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;
using System.Globalization;
using System.IO;
using System.Text;

namespace Viewer
{
  /// <summary>
  /// FormMain の概要の説明です。
  /// </summary>
  public class FormMain : System.Windows.Forms.Form
  {
   private const string _wsdl = "ReportService.asmx";

   private System.Windows.Forms.TextBox reportServerUrl;
   private System.Windows.Forms.Label reportServerUrlLabel;
   private System.Windows.Forms.ColumnHeader 名前;
   private System.Windows.Forms.Button getReportList;
   /// <summary>
   /// 必要なデザイナ変数です。
   /// </summary>
   private System.ComponentModel.Container components = null;

   public FormMain()
   {
     CultureInfo jpCi = new CultureInfo("ja-JP", true);
     jpCi.DateTimeFormat.Calendar = new JapaneseCalendar();
     jpCi.DateTimeFormat.LongDatePattern = "yyyy/MM/dd";
     jpCi.DateTimeFormat.ShortDatePattern = "yy/MM/dd";
     Thread.CurrentThread.CurrentUICulture = jpCi;
     Thread.CurrentThread.CurrentCulture = jpCi;

     //
     // Windows フォーム デザイナ サポートに必要です。
     //
     InitializeComponent();

     //
     // TODO: InitializeComponent 呼び出しの後に、コンストラクタ コードを追加してください。
     //
   }

   /// <summary>
   /// 使用されているリソースに後処理を実行します。
   /// </summary>
   protected override void Dispose( bool disposing )
   {
     if( disposing )
     {
      if (components != null)
      {
       components.Dispose();
      }
     }
     base.Dispose( disposing );
   }

   #region Windows フォーム デザイナで生成されたコード
   /// <summary>
   /// デザイナ サポートに必要なメソッドです。このメソッドの内容を
   /// コード エディタで変更しないでください。
   /// </summary>
   private void InitializeComponent()
   {
    System.Configuration.AppSettingsReader configurationAppSettings = new System.Configuration.AppSettingsReader();
    this.reportServerUrl = new System.Windows.Forms.TextBox();
    this.reportServerUrlLabel = new System.Windows.Forms.Label();
    this.reportItemView = new System.Windows.Forms.ListView();
    this.名前 = new System.Windows.Forms.ColumnHeader();
    this.getReportList = new System.Windows.Forms.Button();
    this.SuspendLayout();
    //
    // reportServerUrl
    //
    this.reportServerUrl.Location = new System.Drawing.Point(112, 16);
    this.reportServerUrl.Name = "reportServerUrl";
    this.reportServerUrl.Size = new System.Drawing.Size(640, 19);
    this.reportServerUrl.TabIndex = 0;
    this.reportServerUrl.Text = ((string)(configurationAppSettings.GetValue("reportServerUrl.Text", typeof(string))));
    //
    // reportServerUrlLabel
    //
    this.reportServerUrlLabel.Location = new System.Drawing.Point(16, 16);
    this.reportServerUrlLabel.Name = "reportServerUrlLabel";
    this.reportServerUrlLabel.Size = new System.Drawing.Size(88, 16);
    this.reportServerUrlLabel.TabIndex = 1;
    this.reportServerUrlLabel.Text = "レポートサーバ";
    //
    // 名前
    //
    this.名前.Text = "name";
    //
    // getReportList
    //
    this.getReportList.Location = new System.Drawing.Point(224, 368);
    this.getReportList.Name = "getReportList";
    this.getReportList.Size = new System.Drawing.Size(80, 32);
    this.getReportList.TabIndex = 3;
    this.getReportList.Text = "取得(&G)";
    this.getReportList.Click += new System.EventHandler(this.getReportList_Click);
    //
    // FormMain
    //
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
    this.ClientSize = new System.Drawing.Size(920, 486);
    this.Controls.Add(this.getReportList);
    this.Controls.Add(this.reportItemView);
    this.Controls.Add(this.reportServerUrlLabel);
    this.Controls.Add(this.reportServerUrl);
    this.Name = "FormMain";
    this.Text = "ReportViewer";
    this.ResumeLayout(false);

   }
   #endregion

   /// <summary>
   /// アプリケーションのメイン エントリ ポイントです。
   /// </summary>
   [STAThread]
   static void Main()
   {
    Application.Run(new FormMain());
   }

   private void getReportList_Click(object sender, System.EventArgs e)
   {
    ReportService.ReportingService rs = new Viewer.ReportService.ReportingService();
    rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
    string path = this.reportServerUrl.Text;
    if(!path.Substring(path.Length - 1).Equals("/"))
    {
     path += "/";
    }    
    path += FormMain._wsdl;
    rs.Url = path;
    MessageBox.Show(path);
    string buffer = "";
    ReportService.CatalogItem[] catalogItem = rs.ListChildren("/", false);
    for(int i = 0; i < catalogItem.Length; i++)
    {
     buffer += catalogItem[i].Name + "\n";
    }
    MessageBox.Show(buffer);
   }
  }
}
--

SQL Server 2000 Reporting Services にはまだまだたくさんの機能があります。
なのでしばらく SQL Server 2000 Reporting Services の記事を連載していこうと思います。

 

ボードリーダーレポート トップページへ
 
PASSJメールニュース 著作権ついて プライバシーポリシー リンクポリシー お問い合わせ
(C) 2005 Professional Association for SQL Server Japan. All rights reserved.