View Full Version : Atlas WebService DI
Aleksei Kachanov
04-20-2006, 10:52 AM
I am having difficulties injecting dependencies into Atlas WebService
How to use DAO objects in Atlas WebService
Bruno Baia
04-20-2006, 01:28 PM
Hi Aleksei,
you can't use DI directly on web services(*.asmx files) like you do with web pages (*.aspx files).
But you can use DI (and AOP) on the service and then export the modified service as a web service using the WebServiceExporter.
There is a example in the SpringAir web sample application :
The web service url :
http://localhost/SpringAir/bookingAgentWebService.asmx
The web service configuration using DAO objects :
Config\Services.xml
Config\Test\Dao.xml
Config\Test\Services.xml
You can find another example in the Calculator sample application.
-Bruno
Aleksei Kachanov
04-20-2006, 01:45 PM
Thanks, Bruno
But to integrate Atlas you needed to use a custom .asmx handler, which would conflict with current spring enabled asmx handler.
How can I resolve this conflict?
Bruno Baia
04-20-2006, 01:55 PM
exactly, i forgot that, sorry.
There is a topic about this issue :
http://forum.springframework.net/viewtopic.php?t=425
It creates a webservicehandler that merge both Microsft Altas and Spring web services handler.
It can help until we got a permanent solution.
-Bruno
Aleksei Kachanov
04-20-2006, 02:01 PM
Thanks, Bruno
How I can understood this code,
this handler split, but not merge Microsft Altas and Spring web services handler.
Bruno Baia
04-20-2006, 02:15 PM
Instead of extending the default ASP.NET WebServiceHandlerFactory (System.Web.Services.Protocols.WebServiceHandlerFa ctory), it extends the Atlas one (Microsoft.Web.Services.ScriptHandlerFactory). So don't know if we can say "split".
Anyway, there is another solutions:
- remove the atlas web service handler if you don't need it
- register Spring web services handler under another extension file name (*.myasmx), but you need to register it under IIS. maybe the "cleanest" solution.
-Bruno
Aleksei Kachanov
04-20-2006, 02:22 PM
I need Atlas web service handler, because I use it in my controls.
But in this WebService I want to use DAO injected by Spring.
But by this solution I can use or Atlas Web Service without injected DAO, or Spring webservice with injected DAO.
DAO implemented by nHibernate.
Bruno Baia
04-20-2006, 02:27 PM
And what about this solution ?
- register Spring web services handler under another extension file name (*.myasmx), but you need to register it under IIS.
Aleksei Kachanov
04-20-2006, 02:29 PM
I don't understant, how it helps me to inject DAO into Atlas Web Service?
djeeg
04-20-2006, 02:53 PM
i use the handler that i posted for mapping asmx files, as in shared hosting, sometimes they will not add the needed extra mapping. The spring docs tell how you can not inject into web services directly, that is why the exporter is used. As the atlas webservice can not be used with the export, the DI will not happen automatically. instead what i do is in the constructor for atlas web services, inject the objects i need manually.
#region IoC
protected IContext context;
public IContext ThisContext {
set { context = value; }
}
#endregion
public SiteBuilderContextWS() {
IApplicationContext ctx = ContextRegistry.GetContext();
if(ctx != null) {
context = (IContext)ctx.GetObject("MyObjectName");
}
}
The setter is not needed, but i like it their to remind myself that this has got dependancies and it looks like all my other DI files. It is not the best solution, but it gets the job down. also you can still have spring map the rest of the webservices you dont use for atlas, so you dont lose that functionality.
Bruno Baia
04-20-2006, 03:09 PM
I don't understant, how it helps me to inject DAO into Atlas Web Service?
Oops, sorry, i was not understanding.
The Atlas web services generates some js scripts and you need them.
So you can use the first solution with the code from the topic :
http://forum.springframework.net/viewtopic.php?t=425
You can replace the code of the current file (src\Spring\Spring.Web\Web\Services\WebServiceHand lerFactory.cs) by the one provided in the topic but i recomend to create another WebServiceHandlerFactory and to put it in another project that references the Atlas dll.
-Bruno
Bruno Baia
04-20-2006, 03:40 PM
As the atlas webservice can not be used with the export, the DI will not happen automatically. instead what i do is in the constructor for atlas web services, inject the objects i need manually.
I take a look to your code, creating a webservicehandlerfactory compatible with Atlas seems a little bit more complexe.
I'll investigate tonight.
-Bruno
Bruno Baia
04-20-2006, 11:50 PM
Aleksei,
don't use this this code, i explain why in the relevant topic :
http://forum.springframework.net/viewtopic.php?p=2240
Sorry to have misunderstood, next time i'll investigate first :oops:
Anyway there is another possible solution using Atlas bridges (*.asbx extensions), have you tried it ?
http://atlas.asp.net/docs/walkthroughs/devscenarios/bridge.aspx
-Bruno
Bruno Baia
06-02-2006, 07:55 AM
Hi,
I forgot to reply to this threads, it can help with search results.
There is now an ASP.NET "Atlas" web services integration (http://forum.springframework.net/showthread.php?t=447) to allow DI and AOP for your ATLAS web services.
-Bruno
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.