View Full Version : Exporting an object in a service using SaoServiceExporter
erijvordt
11-23-2005, 01:11 PM
Hi all,
I am trying to export an object defined in a deployed service using the SaoServiceExporter class. I'm following the procedure described in http://www.springframework.net/doc/reference/html/remoting.html exactly, but it doesn't work. Maybe this is another pecularity with WindowsServices? (see topic "Some questions").
In detail, this is what I have in my service.config:
<system.runtime.remoting>
<application>
<channels>
<channel ref="tcp" port="8073"/>
</channels>
</application>
</system.runtime.remoting>
This is in my service.xml:
<object name="saoScheduler" type="Spring.Remoting.SaoServiceExporter, Spring.Services">
<property name="Service" ref="scheduler"/>
<property name="ServiceName" value="VSNUTaskScheduler"/>
</object>
Object "scheduler" is of class SchedulerImpl which inherits MarshalByRefObject, and implements IScheduler, and this object is defined in service.xml as well as a singleton.
In the client (website), I use this config to import this remote object:
<object name="remoteScheduler" type="Spring.Remoting.SaoFactoryObject, Spring.Services">
<property name="ServiceInterface" value="Deloitte.Service.Scheduler.IScheduler, Deloitte.Service" />
<property name="ServiceUri" value="tcp://localhost:8073/VSNUTaskScheduler" />
</object>
According to the remoting docs, this is all that's needed, however, you guessed it, this doesn't work. I don't see port 8073 being opened (with netstat, tried other ports as well), nor do I see any remoting debug log messages (have set Spring's log4net level to DEBUG) in the service's log files.
Anyone know what's missing/wrong here?
Thanks,
Edwin
Bruno Baia
11-23-2005, 02:49 PM
I make it work a few days ago.
Take a look to the Remoting Quickstart documentation :
http://www.springframework.net/doc/reference/html/remoting-quickstart.html
Here are problems i got when i tested it :
- Service object to be remoted needs to implement 'MarshalByRefObject'
- Model classes used by the Service should be 'Serializable'
- Keep the server alive (look at the main method of the remoting quickstart server application)
- 'ServiceUrl' Property of SaoFactoryObject class changed to 'ServiceUri' (needs a update on documentation ?)
erijvordt
11-23-2005, 05:29 PM
Hmm,
I did all those things. I don't see anything in the quickstart that I missed. I thought that the SaoServiceExporter does what the Main of the server example does, or do I have to call RemotingConfiguration.Configure("ServerApp.exe.config") somewhere in my service?
I assume by 'keep the server alive' you mean returning null from InitializeLifeTimeServices?
Did you also do get this to work in an application deployed from the WindowsService process?
Regards,
Edwin
Bruno Baia
11-23-2005, 05:41 PM
Did you also do get this to work in an application deployed from the WindowsService process?
I used a simple ConsoleApplication for the server application, and i got something like that in the Main method :
RemotingConfiguration.Configure("ServerApp.exe.config");
IApplicationContext ctx = ContextRegistry.GetContext();
Console.WriteLine( "Server started...");
Console.ReadLine();
I assume by 'keep the server alive' you mean returning null from InitializeLifeTimeServices?
With "Console.ReadLine()", i "keep the server alive" until u press any key.
But with a Windows service, u don't need that.
I thought that the SaoServiceExporter does what the Main of the server example does, or do I have to call RemotingConfiguration.Configure("ServerApp.exe.config") somewhere in my service?
Yes, i think that's ur problem, that's why u don't see anything over tcp.
The remote server is not started.
I did all those things. I don't see anything in the quickstart that I missed
nop, u didn't configure the remote server :)
Mark Pollack
11-25-2005, 10:38 PM
Hi,
Thanks Bruno for your answers. I've changed the reference docs to address the points you raised.
- Service to implement MarshalByRefObject (should have dynamic proxy soon :))
- Service arguments to implement Serializable.
- Deployment in console application (placeholder for windows service/IIS)
- Fix ServiceUrl to be ServiceUri
I'm in the process of going over the Spring.Services.WindowsService codebase and I'll post back when I confirm this running inside a windows service. I know that one user has done this so I don't expect a problem.
Once again thanks!
Hope everything is working for you now Edwin.
Cheers,
Mark
Mark Pollack
11-25-2005, 11:30 PM
Hi,
I ran the calculator server inside a windows service without any issues. I used the helper classes in Spring.Services.WindowsService. It could use some clean up w.r.t knowing where the location of the application configuration file is...nevertheless the class looks like
namespace WindowsServiceApp
{
public class CalculatorService
{
public CalculatorService()
{
}
public void Start()
{
RemotingConfiguration.Configure(@"C:\PROJECTS\Spring.Net\build\windows-service\deploy\calculator\bin\service.config");
}
public void Stop()
{
}
}
}
And the XML config is
<objects xmlns="http://www.springframework.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd">
<object name="myCalculator" type="Server.RemotedCalculator, Server">
<property name="Memory" value="10"/>
</object>
<object name="mySaoCalculator" type="Spring.Remoting.SaoServiceExporter, Spring.Services" depends-on="calculatorService">
<property name="Service" ref="myCalculator"/>
<property name="ServiceName" value="MyRemotedCalculator"/>
</object>
<object name="calculatorService"
type="WindowsServiceApp.CalculatorService, WindowsServiceApp"
init-method="Start" destroy-method="Stop">
</object>
</objects>
The application config file was name service.config following conventions for using Spring.Services.WindowsService. Aside from the log4net configuration all that is there is the remoting section
<system.runtime.remoting>
<application>
<channels>
<channel ref="tcp" port="8005" />
</channels>
</application>
</system.runtime.remoting>
I've added this to the remoting quickstart example.
This makes me think there should be some way to execute code before the spring windows service instantiates the context...
Cheers,
Mark
erijvordt
11-29-2005, 11:27 AM
Thanks!
It now works thanks to the call to RemotingConfiguration.Configure().
For the WindowsService, maybe it's an idea to always call this (in the service process code) on startup, since if there is a <system.runtime.remoting> section in the config, it is probably necessary. If there isn't, it won't do any harm either (I think).
Regards,
Edwin
Anonymous
12-02-2005, 08:06 AM
In an application that will be run as a service, one can use
AppDomain.CurrentDomain.BaseDirectory
to get the directory to the config file
fspinazzi
12-28-2005, 05:04 PM
The last CVS contains upgraded support for windows service where remoting configuration is no more needed.
bchebrou
01-20-2006, 04:49 PM
Hi,
This makes me think there should be some way to execute code before the spring windows service instantiates the context...
Cheers,
Mark
I've a problem with windows services and I think it could be linked to your remark. My service starts correctly but in the start method it seems that the AppSettings from the service.config are not loaded. I've the same problem with log4net, so i can't log the startup of my service :(
Do you think is a bug ? :?
Regards,
Benjamin
ps : my version is Spring.NET-20060114-2203
edit : this can be easily reproduced with the example : echo.cs
The log4net configuration is not loaded in the start method
vBulletin® v3.7.3, Copyright ©2000-2009, Jelsoft Enterprises Ltd.