クリックして評価とフィードバックをお寄せください
MSDN
MSDN ライブラリ
.NET 開発
.NET Framework 3.5
.NET Framework 3.5
IContractBehavior メソッド
 ApplyClientBehavior メソッド

  低帯域幅での表示をオンにする
このページは次のバージョンについて記述しています。
Microsoft Visual Studio 2008/.NET Framework 3.5

その他のバージョンについては、以下の情報を参照してください。
.NET Framework クラス ライブラリ
IContractBehavior..::.ApplyClientBehavior メソッド

更新 : 2007 年 11 月

コントラクト全体にわたってクライアントの変更または拡張を実装します。

名前空間 :  System.ServiceModel.Description
アセンブリ :  System.ServiceModel (System.ServiceModel.dll 内)
Visual Basic (宣言)
Sub ApplyClientBehavior ( _
    contractDescription As ContractDescription, _
    endpoint As ServiceEndpoint, _
    clientRuntime As ClientRuntime _
)
Visual Basic (使用法)
Dim instance As IContractBehavior
Dim contractDescription As ContractDescription
Dim endpoint As ServiceEndpoint
Dim clientRuntime As ClientRuntime

instance.ApplyClientBehavior(contractDescription, _
    endpoint, clientRuntime)
C#
void ApplyClientBehavior(
    ContractDescription contractDescription,
    ServiceEndpoint endpoint,
    ClientRuntime clientRuntime
)
Visual C++
void ApplyClientBehavior(
    ContractDescription^ contractDescription, 
    ServiceEndpoint^ endpoint, 
    ClientRuntime^ clientRuntime
)
J#
void ApplyClientBehavior(
    ContractDescription contractDescription,
    ServiceEndpoint endpoint,
    ClientRuntime clientRuntime
)
JScript
function ApplyClientBehavior(
    contractDescription : ContractDescription, 
    endpoint : ServiceEndpoint, 
    clientRuntime : ClientRuntime
)

パラメータ

contractDescription
型 : System.ServiceModel.Description..::.ContractDescription
拡張対象のコントラクトの説明。
endpoint
型 : System.ServiceModel.Description..::.ServiceEndpoint
エンドポイント。
clientRuntime
型 : System.ServiceModel.Dispatcher..::.ClientRuntime
クライアント ランタイム。

すべてのメッセージまたは特定の 1 つの操作について、クライアント ランタイムを表示または変更したり、クライアント ランタイムにカスタム拡張機能を追加したりするには、ApplyClientBehavior メソッドを実装します。クライアントのランタイム オブジェクトで実行できるカスタマイズの詳細については、ClientRuntime および ClientOperation を参照してください。

動作をサービス アプリケーションでのみ使用する場合は、ApplyClientBehavior メソッドで NotImplementedException 例外をスローさせることができます。

このメソッドは、指定されたサービス コントラクトを使用するエンドポイントごとに 1 回呼び出されます。

説明 (各方向に 1 つずつ) では同じ名前の操作が 2 つ存在する場合がありますので注意してください。このため、双方向コントラクトで操作の反復が必要な場合は、エンドポイント ClientRuntime と、CallbackDispatchRuntime プロパティによって返されるエンドポイント間で、メッセージの方向を関連付ける必要があります。

既に他の動作によって一部の操作が追加されているか、ランタイムから削除されている可能性があるので、Operations プロパティにある ClientOperation オブジェクトと同じ数の操作が説明に存在するという保証はありません。

次のコード例は、カスタムの IInstanceProvider 実装が "シングルトン" 動作を提供する ObjectProviderBehavior を呼び出したことを前提としています。これは、常に同じサービス インスタンスを返し、リサイクルはしません。

インスタンス プロバイダのカスタマイズを挿入するために、例では、IContractBehavior を実装するカスタム属性 (SingletonBehaviorAttribute) を実装してカスタム サービス インスタンス プロバイダを挿入する方法を示しています。また、IContractBehaviorAttribute も実装します。これは、その使用を ISampleService コントラクトにバインドします。

C#
public class SingletonBehaviorAttribute : Attribute, IContractBehaviorAttribute, IContractBehavior
{

  #region IContractBehaviorAttribute Members

  public Type TargetContract
  {
    get { return typeof(ISampleService); }
  }

  #endregion

  #region IContractBehavior Members

  public void AddBindingParameters(ContractDescription description, ServiceEndpoint endpoint, System.ServiceModel.Channels.BindingParameterCollection parameters)
  {
    return;
  }

  public void ApplyClientBehavior(ContractDescription description, ServiceEndpoint endpoint, ClientRuntime clientRuntime)
  {
    return;
  }

  public void ApplyDispatchBehavior(ContractDescription description, ServiceEndpoint endpoint, DispatchRuntime dispatch)
  {
    dispatch.InstanceProvider = new ObjectProviderBehavior("Custom ObjectProviderBehavior constructor.");
  }

  public void Validate(ContractDescription description, ServiceEndpoint endpoint)
  {
    return;
  }

  #endregion
}

  • 直前の呼び出し元に対する完全な信頼。このメンバは、部分的に信頼されているコードから使用することはできません。詳細については、「部分信頼コードからのライブラリの使用」を参照してください。

Windows Vista, Windows XP SP2, Windows Server 2003

.NET Framework および .NET Compact Framework では、各プラットフォームのすべてのバージョンはサポートしていません。サポートされているバージョンについては、「.NET Framework システム要件」を参照してください。

.NET Framework

サポート対象 : 3.5、3.0
コミュニティ コンテンツ   コミュニティ コンテンツとは
新しいコンテンツの追加 RSS  注釈
Processing
© 2009 Microsoft Corporation. All rights reserved. 使用条件  |  商標  |  プライバシー
Page view tracker