Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Finally I get the solution.</p> <p>In a Duplex comunication scenario when a callback is made the server becomes the client and vice versa. </p> <p>So on server side when implementing IServiceBehavior inject the message inspector using the CallbackClientRuntime property of the DispatchRuntime foreach EndpointDispatcher.</p> <pre><code>public void ApplyDispatchBehavior(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase) { foreach (ChannelDispatcher item in serviceHostBase.ChannelDispatchers) { foreach (EndpointDispatcher epd in item.Endpoints) { //injecting an inspector in normal call epd.DispatchRuntime.MessageInspectors.Add(new MessageSizerInspector()); //injecting an inspector in callback epd.DispatchRuntime.CallbackClientRuntime.MessageInspectors.Add(new MessageSizerInspector()); } } } </code></pre> <p>On client side when implementing IEndpointBehavior inject the message inspector using the CallbackDispatchRuntime.</p> <pre><code>public void ApplyClientBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.ClientRuntime clientRuntime) { //injecting an inspector in normal call clientRuntime.MessageInspectors.Add(new MessageSizerInspector()); //injecting an inspector in callback clientRuntime.CallbackDispatchRuntime.MessageInspectors.Add(new MessageSizerInspector()); } </code></pre> <p>Then apply the extension as always. </p> <p>In my case I created a class like the following pseudo code</p> <pre><code>public class MessageSizer : Attribute, IServiceBehavior, IEndpointBehavior { ..... } </code></pre> <p>then I applied this attribute to service implementation for the server side inspection and added a behaviorExtensions inside the app.config to setup the endpoint for message inspection on client side.</p> <pre><code>&lt;system.serviceModel&gt; ........... &lt;client&gt; &lt;endpoint address="net.tcp://localhost/MinerDual.svc" binding="netTcpBinding" bindingConfiguration="wsDualMinerNetTcp" contract="WebApplication.IMinerDual" name="NetTcpMinerDual" behaviorConfiguration="Default" /&gt; &lt;/client&gt; &lt;behaviors&gt; &lt;endpointBehaviors &gt; &lt;behavior name="Default"&gt; &lt;messageSizer/&gt; &lt;/behavior&gt; &lt;/endpointBehaviors&gt; &lt;/behaviors&gt; &lt;extensions&gt; &lt;behaviorExtensions&gt; &lt;add name="messageSizer" type="WCFExtensions.MessageSizerElement, WCFExtensions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/&gt; &lt;/behaviorExtensions&gt; &lt;/extensions&gt; &lt;/system.serviceModel&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload