MSDNから:
XML Webサービスクライアントは、XMLWebサービスによって返されるHTTPCookieによって一意に識別されます。XML Webサービスがクライアントのセッション状態を維持するには、クライアントがCookieを永続化する必要があります。クライアントは、CookieContainerの新しいインスタンスを作成し、XML Webサービスメソッドを呼び出す前にそれをプロキシクラスのCookieContainerプロパティに割り当てることにより、HTTPCookieを受信できます。プロキシクラスインスタンスがスコープ外になるときを超えてセッション状態を維持する必要がある場合、クライアントはXMLWebサービスへの呼び出し間でHTTPCookieを永続化する必要があります。たとえば、Webフォームクライアントは、CookieContainerを独自のセッション状態で保存することにより、HTTPCookieを永続化できます。すべてのXMLWebサービスがセッション状態を使用するわけではないため、クライアントはクライアントプロキシのCookieContainerプロパティを使用する必要がない場合があります。
次のコード例は、セッション状態を使用するXMLWebサービスのWebフォームクライアントです。クライアントは、セッションをクライアントのセッション状態に保存することにより、セッションを一意に識別するHTTPCookieを保持します。
<%@ 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>
MSDNhttp ://msdn.microsoft.com/en-us/library/system.web.services.webmethodattribute.enablesession.aspxで完全な詳細をお読みください