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