WSHttpBinding.AllowCookies Egenskap

Definition

Hämtar eller anger ett värde som anger om WCF-klienten automatiskt lagrar och skickar om cookies som skickas av en enda webbtjänst.

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

Egenskapsvärde

trueom automatisk cookies-bearbetning krävs; annars . false

Kommentarer

Inställningen AllowCookies till true är användbar när en klient interagerar med en webbtjänst som använder cookies. Om du har åtkomst till flera tjänster med samma cookie anger AllowCookies du till false och du måste lägga till cookiehuvudet manuellt i varje utgående meddelande. Följande kod visar hur du gör detta:

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

Gäller för