HttpWebClientProtocol.CookieContainer プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > HttpWebClientProtocol.CookieContainer プロパティの意味・解説 

HttpWebClientProtocol.CookieContainer プロパティ

cookie のコレクションを取得または設定します。

名前空間: System.Web.Services.Protocols
アセンブリ: System.Web.Services (system.web.services.dll 内)
構文構文

Public Property CookieContainer As
 CookieContainer
Dim instance As HttpWebClientProtocol
Dim value As CookieContainer

value = instance.CookieContainer

instance.CookieContainer = value
public CookieContainer CookieContainer { get;
 set; }
public:
property CookieContainer^ CookieContainer {
    CookieContainer^ get ();
    void set (CookieContainer^ value);
}
/** @property */
public CookieContainer get_CookieContainer ()

/** @property */
public void set_CookieContainer (CookieContainer
 value)
public function get CookieContainer
 () : CookieContainer

public function set CookieContainer
 (value : CookieContainer)

プロパティ値
Web サービス クライアントの cookie を表す CookieContainer。

解説解説

XML Web サービス メソッドでセッション状態を使用する場合は、XML Web サービス クライアントのセッションを一意に識別する cookie が、応答ヘッダーで XML Web サービス クライアントに戻されます。XML Web サービスがクライアントのセッション状態を維持するためには、クライアントが Cookie を格納する必要があります。クライアントは、XML Web サービス メソッドを呼び出す前に、CookieContainer の新しいインスタンスを作成し、これをプロキシ クラスの CookieContainer プロパティに割り当てることによって、HTTP Cookie を受け取ります。プロキシ クラスのインスタンスがスコープの外に移った後でもセッション状態を維持する必要がある場合、クライアントは XML Web サービスの呼び出しの間で HTTP Cookie を格納する必要があります。たとえば、Web フォーム クライアントは、CookieContainer をそのセッション状態に保存することによって、HTTP Cookie を格納できます。すべての XML Web サービスがセッション状態を使用するわけではないため、クライアントはクライアント プロキシの CookieContainer プロパティを常に使用する必要はありません。このため、XML Web サービスのドキュメントには、セッション状態が使用されるかどうかを記載する必要があります。

使用例使用例

セッション状態を使用する XML Web サービスの Web フォーム クライアントの例を次に示します。クライアントは、セッションを一意に識別する HTTP Cookie をクライアントのセッション状態に保存することによって格納します。

<%@ Page Language="VB" %>
<%@ Import Namespace="System.IO"
 %>
<%@ Import Namespace="System.Net"
 %>

<html>

    <script runat=server>

        Public Sub EnterBtn_Click(src As
 Object, E As EventArgs) 

      ' Create a new instance of a proxy class for your XML Web service.
      Dim su As ServerUsage = new
 ServerUsage()
          Dim cookieJar As CookieContainer

      ' Check to see if the cookies have already been saved for this
 session.
      If (Session("CookieJar")
 Is Nothing) 
        cookieJar= new CookieContainer()
          Else
       cookieJar = Session("CookieJar")
      End If
   

        ' Assign the CookieContainer to the proxy class.
        su.CookieContainer = cookieJar

      ' Invoke an XML Web service method that uses session state and
 thus cookies.
      Dim count As Integer
 = su.PerSessionServiceUsage()         

      ' Store the cookies received in the session state for future retrieval
 by this session.
      Session("CookieJar") = cookieJar

          ' Populate the text box with the results from the call to
 the XML Web service method.
          SessionCount.Text = count.ToString()  
    End Sub
         
    </script>
    <body>
       <form runat=server ID="Form1">
           
             Click to bump up the Session Counter.
             <p>
             <asp:button text="Bump Up Counter"
 Onclick="EnterBtn_Click" runat=server ID="Button1"
 NAME="Button1"/>
             <p>
             <asp:label id="SessionCount"  runat=server/>
          
       </form>
    </body>
</html>
<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Net" %>

<html>

    <script runat="server">

        void EnterBtn_Click(Object Src, EventArgs E) 
    {
      // Create a new instance of a proxy class for your XML Web service.
      ServerUsage su = new ServerUsage();
          CookieContainer cookieJar;

      // Check to see if the cookies have already been saved for this
 session.
      if (Session["CookieJar"] == null)
 
        cookieJar= new CookieContainer();
          else
       cookieJar = (CookieContainer) Session["CookieJar"];

        // Assign the CookieContainer to the proxy class.
        su.CookieContainer = cookieJar;

      // Invoke an XML Web service method that uses session state and
 thus cookies.
      int count = su.PerSessionServiceUsage();         

      // Store the cookies received in the session state for future
 retrieval by this session.
      Session["CookieJar"] = cookieJar;

          // Populate the text box with the results from the call to
 the XML Web service method.
          SessionCount.Text = count.ToString();  
        }
         
    </script>
    <body>
       <form runat=server ID="Form1">
           
             Click to bump up the Session Counter.
             <p>
             <asp:button text="Bump Up Counter" Onclick="EnterBtn_Click"
 runat=server ID="Button1" NAME="Button1"/>
             <p>
             <asp:label id="SessionCount"  runat=server/>
          
       </form>
    </body>
</html>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
HttpWebClientProtocol クラス
HttpWebClientProtocol メンバ
System.Web.Services.Protocols 名前空間
CookieContainer
WebMethodAttribute.EnableSession プロパティ



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

HttpWebClientProtocol.CookieContainer プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



HttpWebClientProtocol.CookieContainer プロパティのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS