0
我有一個WCF服務在我的界面看起來是這樣的:實施IOperationBehavior作爲屬性
[ServiceContract]
public interface IMyService
{
[OperationContract]
[AllowedFileExtension]
void SaveFile(string fileName);
}
我的目標是檢查傳入消息來驗證文件名。所以我AllowedFileExtensionAttribute類看起來是這樣的:
public class AllowedFileExtensionsAttribute : Attribute, IOperationBehavior
{
private readonly string _callingMethodName;
private readonly string[] _allowedFileExtension;
public AllowedFileExtensionsAttribute([CallerMemberName]string callingMethodName = null)
{
_callingMethodName = callingMethodName;
}
public void AddBindingParameters(OperationDescription operationDescription, BindingParameterCollection bindingParameters)
{
}
public void ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation)
{
}
public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation)
{
}
public void Validate(OperationDescription operationDescription)
{
}
}
從例如WCF測試客戶端或一個簡單的控制檯應用程序調用此,則不會調用我的屬性類,它直接進入implmentation。我在這裏做錯了什麼?
我所做的是在'ApplyDispatchBehavior'中,我向'dispatchOperation.ParameterInspectors'添加了一個'IParameterInspector',並在'AfterCall'和'BeforeCall'中實現了攔截。 – Silvermind