更新 : 2007 年 11 月
コントラクト全体にわたってクライアントの変更または拡張を実装します。
名前空間 :
System.ServiceModel.Description
アセンブリ :
System.ServiceModel (System.ServiceModel.dll 内)
Sub ApplyClientBehavior ( _
contractDescription As ContractDescription, _
endpoint As ServiceEndpoint, _
clientRuntime As ClientRuntime _
)
Dim instance As IContractBehavior
Dim contractDescription As ContractDescription
Dim endpoint As ServiceEndpoint
Dim clientRuntime As ClientRuntime
instance.ApplyClientBehavior(contractDescription, _
endpoint, clientRuntime)
void ApplyClientBehavior(
ContractDescription contractDescription,
ServiceEndpoint endpoint,
ClientRuntime clientRuntime
)
void ApplyClientBehavior(
ContractDescription^ contractDescription,
ServiceEndpoint^ endpoint,
ClientRuntime^ clientRuntime
)
void ApplyClientBehavior(
ContractDescription contractDescription,
ServiceEndpoint endpoint,
ClientRuntime clientRuntime
)
function ApplyClientBehavior(
contractDescription : ContractDescription,
endpoint : ServiceEndpoint,
clientRuntime : ClientRuntime
)
すべてのメッセージまたは特定の 1 つの操作について、クライアント ランタイムを表示または変更したり、クライアント ランタイムにカスタム拡張機能を追加したりするには、ApplyClientBehavior メソッドを実装します。クライアントのランタイム オブジェクトで実行できるカスタマイズの詳細については、ClientRuntime および ClientOperation を参照してください。
動作をサービス アプリケーションでのみ使用する場合は、ApplyClientBehavior メソッドで NotImplementedException 例外をスローさせることができます。
このメソッドは、指定されたサービス コントラクトを使用するエンドポイントごとに 1 回呼び出されます。
説明 (各方向に 1 つずつ) では同じ名前の操作が 2 つ存在する場合がありますので注意してください。このため、双方向コントラクトで操作の反復が必要な場合は、エンドポイント ClientRuntime と、CallbackDispatchRuntime プロパティによって返されるエンドポイント間で、メッセージの方向を関連付ける必要があります。
既に他の動作によって一部の操作が追加されているか、ランタイムから削除されている可能性があるので、Operations プロパティにある ClientOperation オブジェクトと同じ数の操作が説明に存在するという保証はありません。
次のコード例は、カスタムの IInstanceProvider 実装が "シングルトン" 動作を提供する ObjectProviderBehavior を呼び出したことを前提としています。これは、常に同じサービス インスタンスを返し、リサイクルはしません。
インスタンス プロバイダのカスタマイズを挿入するために、例では、IContractBehavior を実装するカスタム属性 (SingletonBehaviorAttribute) を実装してカスタム サービス インスタンス プロバイダを挿入する方法を示しています。また、IContractBehaviorAttribute も実装します。これは、その使用を ISampleService コントラクトにバインドします。
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
参照