次の方法で共有


WSHttpBinding.AllowCookies プロパティ

定義

WCF クライアントが 1 つの Web サービスによって送信された Cookie を自動的に格納して再送信するかどうかを示す値を取得または設定します。

public:
 property bool AllowCookies { bool get(); void set(bool value); };
public bool AllowCookies { get; set; }
member this.AllowCookies : bool with get, set
Public Property AllowCookies As Boolean

プロパティ値

true クッキーの自動処理が必要な場合それ以外の場合は false

注釈

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

適用対象