Policy Injection in WCF client proxy

Topics: Policy Injection Application Block
Apr 22, 2008 at 1:22 PM
I'm trying to use the PIAB in my WCF client proxy, to log the calls to my service class. We want to use the PIAB to make it consistent with other parts of our application.

I've been trying to get this to work all afternoon, but it seems that the PIAB just doesn't work here. I've been searching for answers for this, but all I can find is about using the PIAB at the service part of the architecture. We want to use this on the client side. Is there any way to do this? Anybody has experience with this? I can't find anything in the documentation that covers this.

Hope someone can help.
May 16, 2008 at 10:51 PM
Edited May 16, 2008 at 10:51 PM
Hi,

What have you tried? You should be able to wrap your service contract interface with PIAB just like any other interface...

I took a WCF sample, changed the client code to wrap the calculator client object, and the method calls got intercepted. Code looked like this:

   15         static void Main()

   16         {

   17             // Create a calculator

   18             CalculatorClient client = new CalculatorClient();

   19             ICalculator calculator = PolicyInjection.Wrap<ICalculator>(client);

   20 

   21             // Call the Add service operation.

   22             double value1 = 100.00D;

   23             double value2 = 15.99D;

   24             double result = calculator.Add(value1, value2);

   25             Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);


With this matching config (this is 4.0 config, but that would't make a difference)

    8   <policyInjection>

    9     <injectors defaultInjector="Remoting Policy Injector">

   10       <add type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.RemotingInterception.RemotingPolicyInjector, Microsoft.Practices.EnterpriseLibrary.PolicyInjection, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

   11         name="Remoting Policy Injector" />

   12     </injectors>

   13     <policies>

   14       <add name="Policy">

   15         <matchingRules>

   16           <add type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.MatchingRules.TypeMatchingRule, Microsoft.Practices.EnterpriseLibrary.PolicyInjection, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

   17             name="Type Matching Rule">

   18             <matches>

   19               <add match="Microsoft.ServiceModel.Samples.ICalculator"

   20                 ignoreCase="false" />

   21             </matches>

   22           </add>

   23         </matchingRules>

   24         <handlers>

   25           <add logBehavior="BeforeAndAfter" beforeMessage="" afterMessage="Foo bar&#xD;&#xA;"

   26             eventId="0" includeParameterValues="true" includeCallStack="false"

   27             includeCallTime="true" priority="-1" severity="Information"

   28             order="0" type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers.LogCallHandler, Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

   29             name="Logging Handler" />

   30         </handlers>

   31       </add>

   32     </policies>

   33   </policyInjection>


Is this what you were looking for?

Regards,
Fernando


KoenWillemse wrote:
I'm trying to use the PIAB in my WCF client proxy, to log the calls to my service class. We want to use the PIAB to make it consistent with other parts of our application.

I've been trying to get this to work all afternoon, but it seems that the PIAB just doesn't work here. I've been searching for answers for this, but all I can find is about using the PIAB at the service part of the architecture. We want to use this on the client side. Is there any way to do this? Anybody has experience with this? I can't find anything in the documentation that covers this.

Hope someone can help.



May 28, 2008 at 9:58 AM
Hello Fernando,

thank you for your reply, but I had already found the problem. The problem had nothing to do with a WCF proxy, but it had all to do with the explicit interfaces that are generated when you create a proxy with the 'default' settings in Visual Studio. I changed it so that there are always message contracts generated and now it works like a charm.

Regards,
Koen Willemse


fsimonazzi wrote:
Hi,

What have you tried? You should be able to wrap your service contract interface with PIAB just like any other interface...

......

Is this what you were looking for?

Regards,
Fernando