Share via


WSHttpBindingElement.AllowCookies Eigenschaft

Definition

Dient zum Abrufen oder Festlegen eines Werts, der angibt, ob der WCF-Client automatisch alle Cookies speichert und erneut sendet, die von einem einzelnen Webdienst gesendet werden.

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

Eigenschaftswert

Boolean

true, wenn die automatische Verarbeitung von Cookies erforderlich ist; andernfalls false.

Attribute

Hinweise

Das Festlegen AllowCookies von auf true ist nützlich, wenn ein Client mit einem Webdienst interagiert, der Cookies verwendet. Wenn Sie auf mehrere Dienste mit demselben Cookie zugreifen, legen AllowCookies Sie auf false fest, und Sie müssen den Cookieheader jeder ausgehenden Nachricht manuell hinzufügen. Dies wird im folgenden Code veranschaulicht:

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

Gilt für