Three entries per call using LogCallHandler on WCF service [solved]

Oct 27, 2010 at 1:05 PM

With Sarah's help, over on the EntLib project, I've managed to get PolicyInjection working on a Console App.  Now I'm trying to get it working on a WCF app.  I'm creating an instance of Unity in a ServiceHostFactory so that I can have a single instance of it for all calls and I use the container to resolve the TestService class in an IInstanceProvider implementation.  The essential part of that is that Unity resolves the TestService class.

When my TestService class is instantiated, unity provides an instance of an implementation of IWiggalizer.  GetString() on the service calls GetHome() on the Wiggalizer instance.

I've implemented LogCallHandler policy using the Edit Enterprise Library V5 Configuration plug in to Visual Studio.  Initially, I tried a Namespace Matching Rule with a wildcard (as Wiggalizer is in a sub-Namespace).  I got three BEFORE messages from TestService and one BEFORE from Wiggalizer, then one AFTER from Wiggalizer followed by three AFTER messages from TestService.  Strange.

So then I tried two separate policies with Type Matching Rules, one for each class.  I've given the Call Handlers different EventIds and Messages for clarity.  I'm still getting triple messages from the TestService.

Here are extracts from Web.config:

    <container>
      <extension type="Interception"/>

      <register type="IWiggalizer" mapTo="Wiggalizer">
        <interceptor type="InterfaceInterceptor" />
        <policyInjection />
      </register>
      
      <register type="TestService">
        <interceptor type="VirtualMethodInterceptor" />
        <policyInjection />
      </register>
    </container>

It appears that TestService has to be resolved as an implementation, not an interface, so I can't use the same interceptor type.  I've defined aliases for the types and interface.  The other key part is:

  <policyInjection>
    <policies>
      <add name="TracingPolicy">
        <matchingRules>
          <add type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.MatchingRules.TypeMatchingRule, 
Microsoft.Practices.EnterpriseLibrary.PolicyInjection, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            name="Type Matching Rule">
            <matches>
              <add match="Wiggalizer" />
            </matches>
          </add>
        </matchingRules>
        <handlers>
          <add type="Microsoft.Practices.EnterpriseLibrary.Logging.PolicyInjection.LogCallHandler, 
Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            beforeMessage="BEFORE" afterMessage="AFTER" eventId="407" name="Logging Call Handler">
            <categories>
              <add name="General" />
            </categories>
          </add>
        </handlers>
      </add>
      <add name="TracingPolicy2">
        <matchingRules>
          <add type="Microsoft.Practices.EnterpriseLibrary.PolicyInjection.MatchingRules.TypeMatchingRule, 
Microsoft.Practices.EnterpriseLibrary.PolicyInjection, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            name="Type Matching Rule">
            <matches>
              <add match="TestService" />
            </matches>
          </add>
        </matchingRules>
        <handlers>
          <add type="Microsoft.Practices.EnterpriseLibrary.Logging.PolicyInjection.LogCallHandler, 
Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            beforeMessage="BEFORE2" afterMessage="AFTER2" eventId="408"
            name="Logging Call Handler 2">
            <categories>
              <add name="General" />
            </categories>
          </add>
        </handlers>
      </add>
    </policies>
  </policyInjection>

[I've wrapped the "add type=" lines because otherwise it makes such a pig's ear of the display but they're not wrapped in the original file.]

So, any idea why I get 3 entries for the WCF TestService but only 1 entry for the Wiggalizer class?

 

 

 

Oct 28, 2010 at 6:39 AM

I've posted the entire project here: http://cid-22078f9a937627b6.office.live.com/self.aspx/.Public/ConfiguringWCFforSL4withInterception.zip.  The only binaries in the zip are the Prism (for the ViewModel in the Silverlight client), EntLib and Unity ones.

It logs to the standard EntLib Logging database in a local .\SQLEXPRESS instance and to the standard EntLib event source in Event Viewer.

It shows three calls from the WCF service, before and after and one call from the Wiggalizer call, before and after.

Oct 29, 2010 at 4:37 AM

Remove the addition of the Interception extension in the config file and in the UnityServiceHostFactory.CreateSingleInstanceOfContainerForAllUnityServiceHostFactories.  The EnterpriseLibraryCoreExtension automatically adds it.  Here's a related thread discussion in the Entlib forum.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Oct 29, 2010 at 7:42 AM
Edited Oct 29, 2010 at 7:43 AM

Ah.  I searched in this forum for 'double' and 'triple' but didn't find anything relevant (apart from the one who fixed it by recreating his config file, which didn't work for me because I just reintroduced the errors).

Thank you, once again, Sarah, for fixing my problem.  Now, how are you with decorating?  I've got this odd set of corners and I just can't work out how to get the wallpaper in there.  :-)

Oct 29, 2010 at 7:54 AM

You're welcome, glad to be of help.  No, I'm not good at that :)