IContractBehavior.ApplyDispatchBehavior 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
在合約中對客戶進行修改或延長。
public:
void ApplyDispatchBehavior(System::ServiceModel::Description::ContractDescription ^ contractDescription, System::ServiceModel::Description::ServiceEndpoint ^ endpoint, System::ServiceModel::Dispatcher::DispatchRuntime ^ dispatchRuntime);
public void ApplyDispatchBehavior(System.ServiceModel.Description.ContractDescription contractDescription, System.ServiceModel.Description.ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.DispatchRuntime dispatchRuntime);
abstract member ApplyDispatchBehavior : System.ServiceModel.Description.ContractDescription * System.ServiceModel.Description.ServiceEndpoint * System.ServiceModel.Dispatcher.DispatchRuntime -> unit
Public Sub ApplyDispatchBehavior (contractDescription As ContractDescription, endpoint As ServiceEndpoint, dispatchRuntime As DispatchRuntime)
參數
- contractDescription
- ContractDescription
合約說明需修改。
- endpoint
- ServiceEndpoint
揭露合約的端點。
- dispatchRuntime
- DispatchRuntime
就是控制服務執行的派遣執行時。
範例
以下程式碼範例假設有一個 IInstanceProvider 自訂 ObjectProviderBehavior 實作,提供「單例」行為;它總是回傳相同的服務實例,且不會回收。
若要插入實例提供者的自訂功能,範例展示了如何實作一個自訂屬性(SingletonBehaviorAttribute),該屬性可 IContractBehavior 插入自訂服務實例提供者。 它同時實 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
}
備註
實作 ApplyDispatchBehavior 「檢視」、「修改」或「自訂擴充」來支援服務執行時,針對特定合約中的所有訊息或該合約中的某一特定操作。 關於服務應用程式中可進行的客製化細節,請參見 DispatchRuntime 和 DispatchOperation。
如果該行為僅供用戶端應用程式使用,該 ApplyDispatchBehavior 方法可以拋出 NotImplementedException 例外。
此方法對每個使用指定服務合約的端點呼叫一次。
請注意,描述中可以有兩個同名操作(分別在兩個方向),因此如果你必須遍歷合約為雙工合約的操作,必須將端點 DispatchRuntime 與屬性回傳 CallbackClientRuntime 的訊息方向對應起來。
此外,由於其他行為可能已經從執行時新增或移除了一些操作,無法保證描述 DispatchOperation 中的操作數量與屬性中的 Operations 物件數量相同。