I have followed this article and have created MyMessageInspector
and MyEndPointBehavior
clases as 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 to the web.config?
I've added the below 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 in below, it complains:
<serviceBehaviors>
<behavior>
<myMessageInspector/>
Its complain is as below:
Invalid element in configuration. The extension 'myMessageInspector' does not derive from correct extension base type 'System.ServiceModel.Configuration.BehaviorExtensionElement'.
How to add MyEndPointBehavior
to the web.config?