Export (0) Print
Expand All

WSHttpBinding.AllowCookies Property

Gets or sets a value that indicates whether the WCF client will automatically store and resend any cookies sent by a single web service.

Namespace:  System.ServiceModel
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

public bool AllowCookies { get; set; }

Property Value

Type: System.Boolean
True if automatic cookies processing is required; otherwise, false.

Setting AllowCookies to true is useful when a client is interacting with one web service that uses cookies. If you are accessing multiple services with the same cookie, set AllowCookies to false and you will have to manually add the cookie header to each outgoing message. The following code shows how to do this:

MyWebServiceClient client = new MyWebServiceClient();

        using (new OperationContextScope(client.InnerChannel))

            // Extract the cookie embedded in the received web service response
            // and stores it locally
            HttpResponseMessageProperty response = (HttpResponseMessageProperty)
            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;
                HttpRequestMessageProperty.Name] = request;


.NET Framework

Supported in: 4.5.3, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

© 2014 Microsoft