Share via


WSHttpBindingElement.AllowCookies プロパティ

定義

WCF クライアントが単一の Web サービスから送信されたクッキーを自動的に格納し、再送するかどうかを示す値を取得または設定します。

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すると、クライアントが Cookie を使用する 1 つの Web サービスとやり取りしている場合に便利です。 同じ Cookie を使用して複数のサービスにアクセスする場合は、 を にfalse設定AllowCookiesし、各送信メッセージに 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();  
        }  

適用対象