HttpWebClientProtocol.CookieContainer Özellik
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Tanımlama bilgileri koleksiyonunu alır veya ayarlar.
public:
property System::Net::CookieContainer ^ CookieContainer { System::Net::CookieContainer ^ get(); void set(System::Net::CookieContainer ^ value); };
public System.Net.CookieContainer CookieContainer { get; set; }
member this.CookieContainer : System.Net.CookieContainer with get, set
Public Property CookieContainer As CookieContainer
Özellik Değeri
CookieContainer Bir Web Hizmetleri istemcisinin tanımlama bilgilerini temsil eden bir.
Örnekler
Aşağıdaki kod örneği, oturum durumunu kullanan bir XML Web hizmetinin Web Forms istemcisidir. İstemci, oturumu istemcinin oturum durumunda depolayarak oturumu benzersiz olarak tanımlayan HTTP tanımlama bilgisini depolar.
<%@ 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>
<%@ 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>
Açıklamalar
XML Web hizmeti yöntemi oturum durumunu kullanıyorsa, yanıt üst bilgilerinde XML Web hizmeti istemcisinin oturumunu benzersiz olarak tanımlayan bir tanımlama bilgisi geri geçirilir. XML Web hizmetinin bir istemcinin oturum durumunu koruması için istemcinin tanımlama bilgisini depolaması gerekir. İstemciler, XML Web hizmeti yöntemini çağırmadan önce bunun yeni bir örneğini CookieContainer oluşturup bunu proxy sınıfının özelliğine CookieContainer atayarak HTTP tanımlama bilgisini alır. Ara sunucu sınıf örneği kapsam dışına çıktığında oturum durumunu korumanız gerekiyorsa istemcinin HTTP tanımlama bilgisini XML Web hizmetine yapılan çağrılar arasında depolaması gerekir. Örneğin, bir Web Forms istemcisi http tanımlama bilgisini kendi oturum durumuna kaydederek CookieContainer depolayabilir. Tüm XML Web hizmetleri oturum durumunu kullanmadığından ve bu nedenle istemcilerin her zaman bir istemci ara sunucusunun özelliğini kullanması CookieContainer gerekmediğinden, XML Web hizmeti belgelerinde oturum durumunun kullanılıp kullanılmadığı belirtilmelidir.