다음을 통해 공유


WSHttpBindingElement.AllowCookies 속성

정의

WCF 클라이언트가 단일 웹 서비스에서 보낸 쿠키를 자동으로 저장하고 다시 보낼지 여부를 나타내는 값을 가져오거나 설정합니다.

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

속성 값

true자동 쿠키 처리가 필요한 경우 그렇지 않으면 . false

특성

설명

true 설정 AllowCookies 은 클라이언트가 쿠키를 사용하는 하나의 웹 서비스와 상호 작용할 때 유용합니다. 동일한 쿠키를 사용하여 여러 서비스에 액세스하는 경우 쿠키 AllowCookies 헤더를 false 보내는 각 메시지에 수동으로 추가해야 합니다. 다음 코드는 이 작업을 수행하는 방법을 보여줍니다.

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

적용 대상