Rapier-LOOM and Web-Service

Jan 5, 2012 at 8:35 AM

Rapier-LOOM is a great tool, I'm using it to wave some codes with the target class code in visual studio. But I'm wondering Can I use Rapier-LOOM with Web-service?. I tried to wave some aspect code with Web-Service code by creating an instance of Web-Service but it doesn't work. So i hope there will be a discussion of how can we use Rapier-LOOM and Web-Service together.

Coordinator
Jan 5, 2012 at 12:44 PM

Hi areeg, could you please describe, what exactly happened? Usually it is possible to interweave webservice calls. But you have to keep in mind that interweaving occours only on the client side. This means that the aspect will be interwoven with the service proxy and the code will be executet in context of the thread that calls the webservice. But at least the following code snipped should work:

ServiceReference1.IService1 a=Weaver.Create<ServiceReference1.Service1Client>(new MyAspect());
a.WebMethod();

Jan 6, 2012 at 12:41 AM
Edited Jan 6, 2012 at 12:57 PM

Hi, I'm implementing a web service that enables user to make a log out. First I want to define an instance from a service Interface, but it doesn't work the VS environment can't see the interface, so I defined an instance of the service directly, and try to weave it with the aspect class method that in role displays a simple message indicates if aspect success or not (I do all that in client side), I spent weeks trying to weave them together...so I used the code which you gave it to me

ServiceReference1.IService1 a = Weaver.Create<ServiceReference1.Service1Client>(new MyAspect());
a.WebMethod();

but I write it like that:

ServiceReference.Service 1 a = Weaver.Create<ServiceReference.Service1>(new MyAspect());
a.WebMethod(); 

it gives me a result of the service but I can't get the result of the aspect well, and when I'm trying to write the aspect code to return a value different Error messages appear because I tried more than one solution. these errors go away when i make aspect void.

So:

 I want to make the result of aspect appears in the web page when the user use the service I want to make it return a value. Only the result of the service appears but the aspect never appears.

So Is there a solution to make the aspect result appears on the web page? I tried Generic, Around Advice....

those are my codes:

Default.asmx.cs:

WelcomeServ.Service1 a = Weaver.Create<WelcomeServ.Service1>(new AspectClass());

lblaspectres.Text = a.logout();

AspectClass.cs:

[Loom.JoinPoints.IncludeAll]
[Call(Advice.After)] 
//this code make an error when I try to return value because it is void 
public void aspecttestmethod()
{ 
  String.Format("Hello");
 }

 

 

 

 

Coordinator
Jan 9, 2012 at 8:16 PM

You have to access the return value explicitly via a join-point parameter:

[Call(Advice.After)]
public void aspecttestmethod(
[JPRetVal] ref string s)

  s="Hello";
}

In this case, the parameter "s" will be mapped to the return value. If you want to manipulate the return value, then it has to be a "ref" parameter. You can leave out the "ref" but then changes to "s" would not have an effect.

Note, that this aspect method will match only to methods with no parameters that return a string value. If you want to interweave methods with one or mor parameters, you have to use the following pattern:

 

[Call(Advice.After)]
public void aspecttestmethod(
[JPRetVal] ref string s, params object args[])
{
  s="Hello";
}

But this would match only methods that return a string. If you want to have a generic join-point method, you have to write this:

[Call(Advice.After)]
public void aspecttestmethod<T>(
[JPRetVal] ref T s, params object args[])
{
  s=default(T);
}

If you want you can define further restrictions i.e. that only methods returning a "Baz" (this would also include derived types) should be interwoven:

[Call(Advice.After)]
public void aspecttestmethod<T>(
[JPRetVal] ref T s, params object args[]) where s:Baz
{
String.Format("Hello");
}

 

Jan 10, 2012 at 8:58 AM

thank you MR.Schult these options really helped me. but I want to ask about:

  1. I read your paper "LOOM.NET- An Aspect Weaving Tool", and I noticed that in Section 1.2 that the rules of aspect stored in XML file, I know that Rapier-LOOM functionality done through an assembly which has to be linked to the .NET. My question is can I change the value of aspect (this rules) via XML file or I have to change it through the code? And If there, does it adds any performance overhead?
  2. Could you please make a column in the site about FAQ that can help in knowing more about Rapier-LOOM?

I'm very grateful to you, and thank you about your consideration and time.

Coordinator
Apr 5, 2012 at 8:24 AM

Currently I'm implementing the XML-configuration feature. It will look like this:

   <assembly name="Test">
      <type name="Test.A">
        <apply-aspect assemblyqualifiedname="Test.MyAspect, Test">
          <parameter type="int">42</parameter>
        </apply-aspect>
      </type>
    </assembly>

The eqiv. code-based syntax would be:

namespace Test
{
   public MyAspect:AspectAttribute { ... }

   [MyAspect(42)]
   public  class A { ... }
}

For Rapier-LOOM.NET I'm planning to place this XML into a custom section within the app.config file. Gripper-LOOM.NET would get this via a command line parameter.