View Full Version : Windows Services: some questions
erijvordt
10-25-2005, 03:44 PM
Hi,
I should post this in the Windows Services forum, but that doesn't exist, so I'm asking these questions here :-)
1) The service.xml is used to defined the appcontext for a deployed service. Can I use multiple context files, by including multiple files from the service.config (like you can in Web apps's Web.config)? Or can I only use the single service.xml? But what happens if I have both a service.xml and a context file defined in the service.config (as you do in Web.config), do you then have two root app contexts?
2) Is there an easy way to remotely invoke deployed service objects, e.g. from an ASP.Net page? I did see in the tray monitor a call of the form
Activator.GetObject(typeof(ISpringService), "http://localhost:1234/SpringService.soap") as ISpringService
to access the Spring service itself. Can I access the deployed application's objects from this ISpringService, or in another way? I checked the API but couldn't figure it out from there.
Thanks,
--Edwin Rijvordt
erijvordt
10-27-2005, 03:51 PM
Hi,
Awaiting an answer to my previous post, I played around some with a PropertyPlaceHolderConfigurer in my service.xml, but I can't get that to work. If I use the following configurer:
<object id="appPropertyConfigurer" type="Spring.Objects.Factory.Config.PropertyPlaceholderC onfigurer, Spring.Core">
<!--
<property name="locations">
<list>
<value>file://service/deploy/vsnu-scheduler/common.config</value>
</list>
</property>
<property name="configSections">
<list>
<value>commonConfig</value>
</list>
</property>
-->
<property name="Properties">
<name-values>
<add key="dbcs" value="xxxxxx"/>
</name-values>
</property>
</object>
And then refer to the "dbcs" property from another object definition, like this:
<object id="transactionManager" type="Deloitte.Data.Transaction.OleDbTransactionManager, Deloitte.Data">
<property name="ConnectionString">
<value>${dbcs}</value>
</property>
</object>
I keep getting the error that the placeholder 'dbcs' could not be resolved (both with the commented part, or the part that sets 'Properties' directly). Is this something to do with the way WindowsService classes load context files? I tried a lot of things, but cannot get this to work (though in Web.config this works perfectly). Please help. I'm using the latest CVS version of 19-10-2005.
Another question, why do I not get an error when the file specified in the 'Locations' property cannot be found?
Thanks,
--Edwin Rijvordt
Mark Pollack
10-28-2005, 04:54 PM
Hi Edwin,
Sorry for the delay - I'm looking into it. Will get back to you shortly.
Cheers,
Mark
Mark Pollack
10-29-2005, 12:14 AM
Hi Edwin,
The reason property replacement isn't working is that the Spring windows service process creates an IObjectFactory and not an IApplicationContext. The difference being that when an IApplicationContext is created it looks for any objects that implement IObjectPostProcessor (i.e. PropertyPlaceHolderConfigurer) and registers them where as with an lObjectFactory this would normally be done in code 'manually'. Generally speaking the IObjectFactory is a legacy thing, a 'lighter' version of the IApplicationContext but it creaps into Spring.NET usage now and then...
Since an IApplicationContext isn't being created, the property replacement doesn't happen and there is no error when a bad name is specified for the 'Locations' property because the post processor is not executed.
I have made a JIRA issue (http://opensource2.atlassian.com/projects/spring/browse/SPRNET-227) for the windows service to support creating an IApplicationContext instead. I'll ping back here when it is fixed.
As for service.xml vs. service.config, yea I don't see why we don't just use service.config to define everything as we do akin to web.config and App.config. Now you can only use the service.xml as there is no code that is actually creating an IApplicationContext based on what is defined in service.config. If you somehow did this in your own code - yea - you would have two application contexts instantiated. I'd like to review this a bit more and ping the author Federico for his thoughts. For now, just keep using service.xml until we clean this up.
As for the last question, you can use Activator.GetObject as you would normally from code to get a client side proxy for a .NET remoted object or if you like you can use some of the service factory classes to help create an client proxy for a web service (http://www.springframework.net/doc/reference/html/web.html#d0e7071), System. EnterpriseServices serviced component (http://www.springframework.net/doc/reference/html/services.html#services-clientside) or a normal .NET Remoting MarshalByRef (http://www.springframework.net/doc/reference/html/remoting.html#d0e5757) object.
Cheers,
Mark
erijvordt
10-31-2005, 08:17 AM
Thanks sofar,
However, from the stack trace I get, it appears post processing is done, may be a different PropertyPlaceHolder than the one I declare is invoked?
2005-10-27 16:52:20|ERROR|3292|Spring.Services.WindowsService .Common.Deploy.DeployManager.Deploy|0|Failed deploy of application at C:\Work\VSNU\src\VSNUWeb\VSNU.Service\service\depl oy\vsnu-scheduler
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Spring.Objects.Factory.ObjectDefinitionStoreExcept ion: Error registering object with name 'transactionManager' defined in 'file [C:\Work\VSNU\src\VSNUWeb\VSNU.Service\service\dep loy\vsnu-scheduler\service.xml] line 97' : Could not resolve placeholder 'dbcs'.
at Spring.Objects.Factory.Config.PropertyPlaceholderC onfigurer.ProcessProperties(IConfigurableListableO bjectFactory factory, NameValueCollection props)
at Spring.Objects.Factory.Config.PropertyResourceConf igurer.PostProcessObjectFactory(IConfigurableLista bleObjectFactory factory)
at Spring.Services.WindowsService.Common.Application. DefaultFactory(IApplication application)
at Spring.Services.WindowsService.Common.Application. get_ObjectFactory()
at Spring.Services.WindowsService.Common.ApplicationH ost..ctor(AppDomain domain, IApplication application)
--- End of inner exception stack trace ---
Apart from that, I discovered the <import> element I can use in context files to include other files, like this:
<import resource="file://~/Objects.xml"/>
This loads the objects from a file relative to the deployed service's directory. So I can use that in the meantime to achieve more or less the same.
Regards,
Edwin
Mark Pollack
10-31-2005, 01:20 PM
Hi Edwin,
Nope that is the right one. Yea, import will help you - sorry I didn't mention it - I thought you implied that in your email. I'll ping back here once I have some more information.
Cheers,
Mark
Mark Pollack
11-17-2005, 11:06 AM
Hi Edwin
2) Is there an easy way to remotely invoke deployed service objects, e.g. from an ASP.Net page? I did see in the tray monitor a call of the form
Activator.GetObject(typeof(ISpringService), "http://localhost:1234/SpringService.soap") as ISpringService
The 1.1 preview release has the .NET Remoting helper classes (http://www.springframework.net/doc/reference/html/remoting.html) included. With those, you can use dependency injection on your ASP.NET pages to get a reference to a .NET Remoted object. Still need to review the WindowsService code....
Cheers,
Mark
erijvordt
11-23-2005, 12:58 PM
Hi all,
Some progress from my part: I changed the DefaultFactory method in Spring.Services.WindowsService.Common.Application. cs to this:
public static IConfigurableListableObjectFactory DefaultFactory (IApplication application)
{
XmlApplicationContext factory = new XmlApplicationContext(application.ServiceXmlFullPa th);
PropertyPlaceholderConfigurer configurer = DefaultConfigurer (application);
factory.AddObjectFactoryPostProcessor(configurer);
factory.ObjectFactory.PreInstantiateSingletons();
return factory.ObjectFactory;
}
and now I can use PropertyPlaceHolderConfigurers in my service.xml. I have one there which I tell to read the "appSettings" setting of my Web.config (of the site that accompanies the service), so I only have one place with those settings. In addition, I include the other context files (with business components needed by the server) from the Web app as well.
Only problem with this fix is that the DefaultConfigurer added above does no longer work, meaning you don't have access to the ${spring.services.application.fullpath} property (and another one I forgot) anymore. But now we only have to do one setting manually after installation (the path to the service directory, so the <imports> in the service.xml work), which makes it much more workable. Any idea to make the DefaultConfigurer work as well?
Hope this is of use to someone. Is anyone still working on WindowsServices? It appears Federico Spinazzi is not actively working on this anymore...
Regards,
Edwin
fspinazzi
11-23-2005, 02:02 PM
Edwin,
I'm Federico and while I'm not actively working on this I want to help with this and probably rewrite some parts in light of your needs.
The best thing we can do is to collect issues via JIRA, so feel free to create them as needed or to send a message to the developer list (far easier for me to follow) with the enanchements you need.
I'll promise I'll take care of them, starting from the one created by Mark.
Thanks for the interest in windows service!!
Federico
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.