Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

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:
property bool AllowCookies {
	bool get();
	void set(bool value);
}

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

.NET Framework
Available since 3.0
Return to top
Show:
© 2017 Microsoft