WSHttpBinding.AllowCookies Propiedad

Definición

Obtiene o establece un valor que indica si el cliente WCF almacenará y volverá a enviar automáticamente las cookies enviadas por un solo servicio 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

Valor de propiedad

Boolean

Es true si se necesita el procesamiento automático de las cookies; si no, es false.

Comentarios

Establecer AllowCookies en true es útil cuando un cliente interactúa con un servicio web que usa cookies. Si accede a varios servicios con la misma cookie, establezca AllowCookies en false y tendrá que agregar manualmente el encabezado de cookie a cada mensaje saliente. El código siguiente muestra cómo hacerlo:

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

Se aplica a