WSHttpBindingElement.AllowCookies Proprietà

Definizione

Ottiene o imposta un valore che indica se il client WCF archivierà e invierà nuovamente in modo automatico i cookie inviati da un singolo servizio Web.

public:
 property bool AllowCookies { bool get(); void set(bool value); };
[System.Configuration.ConfigurationProperty("allowCookies", DefaultValue=false)]
public bool AllowCookies { get; set; }
[<System.Configuration.ConfigurationProperty("allowCookies", DefaultValue=false)>]
member this.AllowCookies : bool with get, set
Public Property AllowCookies As Boolean

Valore della proprietà

Boolean

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

Attributi

Commenti

AllowCookiesL'impostazione su è utile quando un client true interagisce con un servizio Web che usa i cookie. Se si accede a più servizi con lo stesso cookie, impostare su e sarà necessario aggiungere manualmente l'intestazione del AllowCookies cookie a ogni messaggio in false uscita. Nel codice seguente viene illustrato 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