how can i add IOperationBehavior programmatically when running on iis ? not on custom wcf host.
thanks
Ali TAKAVCI
how can i add IOperationBehavior programmatically when running on iis ? not on custom wcf host.
thanks
Ali TAKAVCI
You need to build a custom service host, then set your .svc file to use it. In the custom service host you can do whatever you like to the service before it starts, including setting behaviours. Because you want to use operation behaviours you should do it in the OnOpening() method - as the service factory applies resets the operation behaviours after endpoint behaviours are configured. You will be able to iterate through the endpoints and the operations in OnOpening.
You could attach it as an attribute:
public class CustomInspectorAttribute : Attribute, IOperationBehavior, IParameterInspector
{
#region IOperationBehavior Members
public void AddBindingParameters(OperationDescription operationDescription, BindingParameterCollection bindingParameters)
{
}
public void ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation)
{
// Attribute could be used on client side
clientOperation.ParameterInspectors.Add(this);
}
public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation)
{
// Attribute could be used on server side
dispatchOperation.ParameterInspectors.Add(this);
}
public void Validate(OperationDescription operationDescription)
{
}
#endregion
#region IParameterInspector Members
public void AfterCall(string operationName, object[] outputs, object returnValue, object correlationState)
{
// Do something with returned values from operation
}
public object BeforeCall(string operationName, object[] inputs)
{
// Do something with incoming parameters before invoking actual operation
return null;
}
#endregion
}
And attach the attribute to an operation
[ServiceContract]
public interface ICustomServiceContract
{
[CustomInspector]
[OperationContract]
void MyOperation();
}