WSHttpBinding.AllowCookies Vlastnost

Definice

Získá nebo nastaví hodnotu, která určuje, zda klient WCF automaticky uloží a znovu odešle všechny soubory cookie odeslané jednou webovou službou.

public:
 property bool AllowCookies { bool get(); void set(bool value); };
public bool AllowCookies { get; set; }
member this.AllowCookies : bool with get, set
Public Property AllowCookies As Boolean

Hodnota vlastnosti

trueje-li požadováno automatické zpracování souborů cookie; v opačném případě . false

Poznámky

true Nastavení AllowCookies je užitečné, když klient komunikuje s jednou webovou službou, která používá soubory cookie. Pokud přistupujete k více službám se stejným souborem cookie, nastavte AllowCookies a false budete muset do každé odchozí zprávy ručně přidat hlavičku souboru cookie. Následující kód ukazuje, jak to udělat:

MyWebServiceClient client = new MyWebServiceClient();

        using (new OperationContextScope(client.InnerChannel))
        {
            client.DoSomething();

            // Extract the cookie embedded in the received web service response
            // and stores it locally
            HttpResponseMessageProperty response = (HttpResponseMessageProperty)
            OperationContext.Current.IncomingMessageProperties[
                HttpResponseMessageProperty.Name];
            sharedCookie = response.Headers["Set-Cookie"];
        }

        MyOtherWebServiceClient otherClient = new MyOtherWebServiceClient();

        using (new OperationContextScope(otherClient.InnerChannel))
        {
            // Embeds the extracted cookie in the next web service request
            // Note that we manually have to create the request object since
            // since it doesn't exist yet at this stage
            HttpRequestMessageProperty request = new HttpRequestMessageProperty();
            request.Headers["Cookie"] = sharedCookie;
            OperationContext.Current.OutgoingMessageProperties[
                HttpRequestMessageProperty.Name] = request;

            otherClient.DoSomethingElse();
        }

Platí pro