WSHttpBindingElement.AllowCookies Eigenschap

Definitie

Hiermee wordt een waarde opgehaald of ingesteld die aangeeft of de WCF-client automatisch cookies opslaat en opnieuw verzendt die door één webservice worden verzonden.

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

Waarde van eigenschap

true indien automatische verwerking van cookies vereist is; anders, false.

Kenmerken

Opmerkingen

Instelling AllowCookies is true handig wanneer een client communiceert met één webservice die gebruikmaakt van cookies. Als u meerdere services met dezelfde cookie opent, moet u deze AllowCookiesfalse handmatig toevoegen aan elk uitgaand bericht. In de volgende code ziet u hoe u dit doet:

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

Van toepassing op