I followed in this article and created the clusters MyMessageInspector
and MyEndPointBehavior
, as shown below:
public class MyMessageInspector : IDispatchMessageInspector { public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext) { Console.WriteLine("Incoming request: {0}", request); return null; } public void BeforeSendReply(ref Message reply, object correlationState) { } } public class MyEndPointBehavior : IEndpointBehavior { #region IEndpointBehavior Members public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters) { } public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime) { } public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher) { ChannelDispatcher channelDispatcher = endpointDispatcher.ChannelDispatcher; if (channelDispatcher != null) { foreach (EndpointDispatcher ed in channelDispatcher.Endpoints) { ed.DispatchRuntime.MessageInspectors.Add(new MyMessageInspector()); } } } public void Validate(ServiceEndpoint endpoint) { } #endregion }
How to add MyEndPointBehavior in web.config?
I have added the following extensions:
<extensions> <behaviorExtensions> <add name="myMessageInspector" type="MessageInspectorProject.MyEndPointBehavior, MessageInspectorProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/> </behaviorExtensions> </extensions>
But when I try to use it below, he complains:
<serviceBehaviors> <behavior> <myMessageInspector/>
His complaint is as follows:
Invalid item in configuration. The extension "myMessageInspector" does not come from the correct base extension type "System.ServiceModel.Configuration.BehaviorExtensionElement".
How to add MyEndPointBehavior
in web.config?
source share