Where is this the right place to programmatically implement IOperationBehavior

How can I add IOperationBehavior programmatically when working on iis? not on the wcf user host.

thanks

Ali TAKAVKI

+3
source share
2 answers

You need to create a user host and then install the .svc file for it. On the user service host, you can do whatever you want before you start it, including customizing the behavior. Since you want to use the behavior of operations, you must do this in the OnOpening () method - as you apply the factory service, the behavior of the operation is reset after adjusting the behavior of the endpoint. You can iterate through endpoints and operations in OnOpening.

+3
source

You can 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 the operation

 [ServiceContract] public interface ICustomServiceContract { [CustomInspector] [OperationContract] void MyOperation(); } 
+8
source

Source: https://habr.com/ru/post/1432926/


All Articles