WSHttpBinding.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); };
public bool AllowCookies { get; set; }
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.

Hinweise

Die Einstellung AllowCookies ist true nützlich, wenn ein Client mit einem Webdienst interagiert, der Cookies verwendet. Wenn Sie auf mehrere Dienste mit demselben Cookie zugreifen, AllowCookies false müssen Sie den Cookie-Header manuell zu jeder ausgehenden Nachricht 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