Condividi tramite


WSHttpBinding.AllowCookies Proprietà

Definizione

Ottiene o imposta un valore che indica se il client WCF archivierà e reinvierà automaticamente i cookie inviati da un singolo servizio Web.

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

Valore della proprietà

true se è necessaria l'elaborazione automatica dei cookie; in caso contrario, false.

Commenti

L'impostazione su AllowCookiestrue è utile quando un client interagisce con un servizio Web che usa i cookie. Se si accede a più servizi con lo stesso cookie, impostare su AllowCookiesfalse e sarà necessario aggiungere manualmente l'intestazione del cookie a ogni messaggio in uscita. Il codice seguente illustra come eseguire questa operazione:

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();
        }

Si applica a