Share via


WSHttpBindingElement.AllowCookies Propriedade

Definição

Obtém ou define um valor que indica se o cliente WCF armazenará e reenviará automaticamente cookies enviados por um único serviço 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

Valor da propriedade

Boolean

true se o processamento automático de cookies for necessário; caso contrário, false.

Atributos

Comentários

AllowCookiesA configuração para true é útil quando um cliente está interagindo com um serviço Web que usa cookies. Se você estiver acessando vários serviços com o mesmo cookie, defina AllowCookies como false e você precisará adicionar manualmente o cabeçalho do cookie a cada mensagem de saída. O código a seguir mostra como fazer isso:

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

Aplica-se a