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

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

WebMethodAttribute.EnableSession プロパティ

XML Web サービス メソッドに対してセッション状態が有効かどうか示します

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

Dim instance As WebMethodAttribute
Dim value As Boolean

value = instance.EnableSession

instance.EnableSession = value
public bool EnableSession { get;
 set; }
public:
property bool EnableSession {
    bool get ();
    void set (bool value);
}
/** @property */
public boolean get_EnableSession ()

/** @property */
public void set_EnableSession (boolean value)
public function get EnableSession
 () : boolean

public function set EnableSession
 (value : boolean)

プロパティ
XML Web サービス メソッドに対してセッション状態が有効である場合true既定値false です。

解説解説

ASP.NET HttpSessionState オブジェクト内にセッション状態格納するには、EnableSession プロパティtrue設定してXML Web サービスWebService から継承し、WebMethodAttribute を、XML Web サービス メソッド適用する必要がありますXML Web サービス メソッドに対してセッション状態不要な場合は、セッション状態無効にすると、パフォーマンスを向上でます。

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

使用例使用例

セッション状態使用して特定のセッションXML Web サービス メソッド SessionHitCounterアクセスした回数判断する例を次に示します

<%@ WebService Language="VB" Class="Util"
 %>
 
Imports System.Web.Services

Public Class Util
    Inherits WebService
    
    <WebMethod(Description := "Per session Hit Counter",
 _
        EnableSession := True)> _
    Public Function SessionHitCounter() As
 Integer
        
        If Session("HitCounter")
 Is Nothing Then
            Session("HitCounter") = 1
        Else
            Session("HitCounter") = CInt(Session("HitCounter"))
 + 1
        End If
        Return CInt(Session("HitCounter"))
    End Function
End Class

<%@ WebService Language="C#" Class="Util" %>
 
 using System.Web.Services;
 
 public class Util: WebService {
   [ WebMethod(Description="Per session Hit Counter",EnableSession=true)]
    public int SessionHitCounter() {
       if (Session["HitCounter"] == null)
 {
          Session["HitCounter"] = 1;
       }
       else {
          Session["HitCounter"] = ((int) Session["HitCounter"])
 + 1;
          }
       return ((int) Session["HitCounter"]);
    }   
 }

セッション状態使用する 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>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
WebMethodAttribute クラス
WebMethodAttribute メンバ
System.Web.Services 名前空間
CookieContainer



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

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

   

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



WebMethodAttribute.EnableSession プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS