Results 1 to 7 of 7

Thread: Logging via AOP in WCF service

  1. #1
    Join Date
    Jun 2007
    Posts
    3

    Default Logging via AOP in WCF service

    Hi,

    I have been using dependency injection described by Orand under http://orand.blogspot.com/2006/10/wc...injection.html.

    Now I'd like to integrate logging via AOP into my service class. Therefore I think it's necessary to "wrap" my service object as Target of a ProxyFactoryObject. But how do I have to "connect" it with the requirements of the WCF (definition of endpoints etc.)?

    Currently my implementation looks like this:

    1. App.config:

    <spring>
    ..
    <objects xmlns="http://www.springframework.net">
    <object id="loggingAroundAdvice" type="MyProject.Spring.LoggingAroundAdvice, MyProject">
    <property name="Logger" value="MyService" />
    </object>
    <object id="myService" type="Spring.Aop.Framework.ProxyFactoryObject">
    <property name="Target"><object type="MyProject.MyService, MyProject"/></property>
    <property name="InterceptorNames">
    <list><value>loggingAroundAdvice</value></list>
    </property>
    </object>
    </objects>
    </spring>
    ..
    <system.serviceModel>
    <services>
    <service name="MyProject.MyService">
    <endpoint address="MyServiceBasic" binding="basicHttpBinding" contract="MyProject.IMyService" />
    </service>
    </services>
    </system.serviceModel>

    2. Providing ProxyFactoryObject for my service (SpringInstanceProvider):

    public class SpringInstanceProvider : IInstanceProvider
    {
    private Type _serviceType;

    public SpringInstanceProvider(Type serviceType)
    {
    _serviceType = serviceType;
    }

    public object GetInstance(InstanceContext instanceContext, Message message)
    {
    object result = null;
    IApplicationContext context = ContextRegistry.GetContext();
    string[] objectNames = context.GetObjectNamesForType(typeof(ProxyFactoryO bject), true, true);
    foreach (string name in objectNames)
    {
    ProxyFactoryObject factory = (ProxyFactoryObject)context.GetObject(name);
    if (factory.TargetSource.TargetType.Equals(_serviceTy pe))
    {
    if (result == null)
    {
    result = factory.GetObject();
    break;
    }
    }
    }
    return result;
    }
    }

    3. Creation of ServiceHost:

    IMyService myService = (IMyService)new SpringInstanceProvider(typeof(MyService)).GetInsta nce(null);
    using (ServiceHost host = new ServiceHost(myService, baseAdresses))
    {
    host.Open();
    ..
    }


    By this way no endpoints can be found by the host because the service object is not of the desired type but a proxy object ..

    Thanks for any hint!

  2. #2
    Join Date
    Oct 2005
    Location
    Toulouse, France
    Posts
    1,407

    Default

    Hi,

    You should take a look to the WCF integration we made, because it allows DI and AOP.
    Get the latest nightly build, and take a look to the WcfQuickStart.


    HTH,
    Bruno
    My english is as poor as my taylor is rich

  3. #3
    Join Date
    Jun 2007
    Posts
    3

    Default Logging for method with out parameter

    Thanks for the hint!


    Now I have a WCF service method declaring one or more out parameters and a return value.

    When I try to call this method the method invocation.Proceed() within my method interceptor throws a fatal error that it cannot proceed.

    How can I add the logging functionality via AOP to those service methods?

    Thanks in advance!

  4. #4
    Join Date
    Oct 2005
    Location
    Toulouse, France
    Posts
    1,407

    Default

    Hi,

    Are you using Spring.Net 1.1 RC1 ?

    - Bruno
    My english is as poor as my taylor is rich

  5. #5
    Join Date
    Jun 2007
    Posts
    3

    Default

    I'm using Spring.NET-1.1.0 Preview 3.

  6. #6
    Join Date
    Oct 2005
    Location
    Belgium
    Posts
    213

    Default

    I believe out parameters where not supported then, use RC1 or the latest build.

  7. #7
    Join Date
    Oct 2005
    Location
    Toulouse, France
    Posts
    1,407

    Default

    Hi,

    Quote Originally Posted by .ben View Post
    I believe out parameters where not supported then, use
    RC1 or the latest build.
    What you Believe is true

    slein, read Chapter 4. Moving from M2 to RC1 while updating to RC1.

    - Bruno
    My english is as poor as my taylor is rich

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •