PDA

View Full Version : WebServiceHandlerFactory not creating the AOP Proxy


yagiz
10-19-2006, 06:10 PM
Hi,

We are developing an application using Web Services in .NET 2.0 (using Visual Studio 2005 for web application projects template) and Spring.AOP. We've come across an unexpected issue while exporting the AOP Proxy as a Web Service.

We have a WebService called MembershipService.asmx that implements the interface IMembershipService. We want to apply security to every method in this webservice and we chose AOP to intercept the execution and place queries to our SecurityManager. We created a class called SecurityInterceptor that implements the IMethodInterceptor.

So the Web.Config look like:


<system.web>
<httpHandlers>
<clear/>
<add verb="*" path="*.asmx" type="Spring.Web.Services.WebServiceHandlerFactory, Spring.Web" />
</httpHandlers>
<httpModules>
<add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web" />
</httpModules>
………………

<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core" />
</sectionGroup>

…………………

<spring>
<context type="Spring.Context.Support.WebApplicationContext, Spring.Web">
<resource uri="file://C:\Dev\App\Src\App.MemberShip.Web.Service\Security Objects.xml" />
</context>
</spring>


And in the Spring context we have:


<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net" >
<object name="MembershipService.asmx" type="App.MembershipService, App.MemberShip.Web.Service" abstract="true"/>
<object id="SecurityAdvice"
type=" App.MemberShip.Web.Service.SecurityInterceptor, App.MemberShip.Web.Service"/>

<object id="MyMembershipService" type=" App.MemberShip.Web.Service.MembershipService, App.MemberShip.Web.Service"/>

<object id="MyMembershipServiceProxy" type="Spring.Aop.Framework.ProxyFactoryObject, Spring.Aop">
<property name="TargetName" value="MyMembershipService"/>
<property name="IsSingleton" value="true"/>
<property name="InterceptorNames">
<list>
<value>SecurityAdvice</value>
</list>
</property>
</object>

<object id="MyMemberShipServiceExporter" type="Spring.Web.Services.WebServiceExporter, Spring.Web">
<property name="TargetName" value="MyMembershipServiceProxy"/>
<property name="Name" value="MyMembershipService"/>
<property name="Namespace" value="http://decaresystems.ie/daisy/membership/2006"/>
<property name="Description" value="Membership Service"/>
<property name="Interfaces">
<list>
<value>App.MemberShip.Web.Service.IMembershipService</value>
</list>
</property>
</object>


If we use XmlObjectFactory to get the WebService instance, everything works fine:


IApplicationContext ctx = ContextRegistry.GetContext();
IMembershipService i=ctx.GetObject("MyMemberShipServiceExporter") as IMembershipService;
i.GetSubscribersBySsn(ssn);


However, if we call the WebService through a Web request, Spring.NET HttpHandlerFactory is invoked but it just creates the real WebService and not the Proxy. Therefore we cannot use AOP.
We tried to put a “Response.Write” within the WebServiceHandlerFactory and we noticed that the request is served with this factory without issues… So we don’t know why this factory is not creating the AOP Proxy…

Are we missing anything? Any ideas?
Thanks,

- Yagiz -
http://blog.decaresystems.ie

Bruno Baia
10-19-2006, 08:56 PM
Hi,


If you are using one of the latest nightly build, you should apply those configuration changes :
NOTE: Configuration changes for Spring.Web (http://forum.springframework.net/showthread.php?t=697)
But there is no impact here.


Then, you don't need to create any *.asmx files, Spring just needs a Business object implementing an interface to export as a Web Service, so you can remove the *.asmx file and delete the definition from Spring :

<object name="MembershipService.asmx" type="App.MembershipService, App.MemberShip.Web.Service" abstract="true"/>



And finally, your web service should be available at this url :
http://myapp.com/<virtual directory>/MyMemberShipServiceExporter.asmx


You can also take a look to SpringAir and SpringCalculator samples.
They are both using WebServiceExporter.


Hope this helps,
Bruno

yagiz
10-20-2006, 11:03 AM
Merci Bruno,

We'll give it a try. ;)

yagiz
10-20-2006, 11:18 AM
It works! Perfect!
Thanks! ;)