WSHttpBindingElement.AllowCookies 属性

定义

获取或设置一个无论 WCF 客户端是否将自动存储并通过单个网页服务重新发送任何 cookie 的值。

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

属性值

Boolean

true 如果需要自动 cookie 操作;否则,false

属性

注解

AllowCookies 客户端与一个使用 Cookie 的 Web 服务交互时,将 true 设置为 非常有用。 如果使用同一 Cookie 访问多个服务,请设置为 ,并且必须手动将 AllowCookies false Cookie 标头添加到每个传出消息。 以下代码演示了如何执行此操作:

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

适用于