biz-Streamマニュアル Webサービスサーバ ガイド 第12章 サンプルプログラム(.NET) 12.12 リポジトリのディレクトリを削除するサンプル(WCF)

12.12 リポジトリのディレクトリを削除するサンプル(WCF)

概要

リポジトリのディレクトリを削除するサンプルプログラムです。


スタブクラスの準備

事前に『10.2.6 .NET で開発するための環境構築』の手順を実行します。


サンプル構成

項目 ファイルパス
ソースサンプル <bswss-client_home>/sample/dotNET/wcf/WSS_WCF_Sample12.aspx.cs サンプル1

ソースサンプル

    using System;
    using System.ServiceModel;
    using System.ServiceModel.Channels;
    using System.Web;
    using BizStreamWebApplication.CmsServiceReference;

    namespace BizStreamWebApplication
    {
        public partial class WSS_WCF_Sample12 : System.Web.UI.Page
        {
            // Webサービスサーバのホスト名
            const string WSS_HOST_NAME = "wsssrv";

            // Webサービスのエンドポイントプリフィックス
            const string WSS_SERVICE_LOCATION = "http://" + WSS_HOST_NAME + ":8080/axis2/services";

            // BASIC認証のユーザ名
            const string USER_NAME = "bizuser1";

            // BASIC認証のパスワード
            const string PASSWORD = "bizuser1";

            // 監査ロギング用のユーザ定義
            const string USER_DEF = "AAA";

            // 削除するフォルダパス
            const string TARGET_FOLDER_PATH = "/Sample11_WCF";


            protected void Page_Load(object sender, EventArgs e)
            {
                // リポジトリ内のディレクトリを削除
                removeDir();

                // ブラウザに結果を表示
                Response.Clear();
                Response.ContentType = "text/html;charset=UTF-8";
                Response.Write("<HTML><HEAD><TITLE>WSS_WCF_Sample12</TITLE></HEAD><BODY>");
                Response.Write("正常終了しました。<BR>");
                Response.Write("リポジトリから削除されたディレクトリ: " + TARGET_FOLDER_PATH);
                Response.Write("</BODY></HTML>");
                Response.Flush();
                HttpContext.Current.ApplicationInstance.CompleteRequest();
            }

            private success removeDir()
            {
                // クライアントを生成
                cmsPortTypeClient client =
                    new cmsPortTypeClient("CmsSOAP11port",
                        WSS_SERVICE_LOCATION + "/cms?UserDef=" + USER_DEF);

                // 認証の設定
                BindingElementCollection elements = client.Endpoint.Binding.CreateBindingElements();
                elements.Find<HttpTransportBindingElement>().AuthenticationScheme =
                    System.Net.AuthenticationSchemes.Basic;
                client.ClientCredentials.UserName.UserName = USER_NAME;
                client.ClientCredentials.UserName.Password = PASSWORD;

                // MTOMを有効化
                elements.Remove<TextMessageEncodingBindingElement>();
                MtomMessageEncodingBindingElement mtom = new MtomMessageEncodingBindingElement();
                mtom.ReaderQuotas.MaxStringContentLength = 100000;
                elements.Insert(0, mtom);
                elements.Find<HttpTransportBindingElement>().KeepAliveEnabled = false;
                client.Endpoint.Binding = new CustomBinding(elements);

                // リクエストメッセージの作成
                deleteRequest request = new deleteRequest();
                request.Value = TARGET_FOLDER_PATH;

                // リクエストを送信
                return client.delete(request);
            }
        }
    }