WSHttpBinding.AllowCookies Propriété

Définition

Obtient ou définit une valeur qui indique si le client WCF stocke et renvoie automatiquement les cookies envoyée par un service Web unique.

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

Valeur de propriété

Boolean

true si le traitement automatique des cookies est requis, sinon, false.

Remarques

true La définition AllowCookies est utile lorsqu’un client interagit avec un service web qui utilise des cookies. Si vous accédez à plusieurs services avec le même cookie, définissez-le AllowCookies false et vous devrez ajouter manuellement l’en-tête de cookie à chaque message sortant. Le code suivant illustre comment procéder :

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

S’applique à