PDA

View Full Version : Windows Service and Spring.Remoting.RemotingConfigurer



oz_ko
10-25-2006, 05:39 AM
Hi

I'm in the process of building a remote server in a Windows Service and there is a slight problem with the RemotingConfigurer.

It seems that the filename property must be an absolute path eg:


<object type="Spring.Remoting.RemotingConfigurer, Spring.Services">
<property name="Filename" value="C:\\Documents and Settings\\Oz\\My Documents\\Visual Studio 2005\\Projects\\MyService\\MyService\\bin\\Debug\\ MyService.exe.config" />
</object>


Defining the configuration file as:


<object type="Spring.Remoting.RemotingConfigurer, Spring.Services">
<property name="Filename" value="MyService.exe.config" />
</object>

Results in a System.IO.FileNotFoundException.

While i can live with it, would it possible to resolve the filename prior to passing it to RemotingConfiguration.Configure(_filename, _ensureSecurity);

Thanks,
Oz

oz_ko
10-25-2006, 06:50 AM
I don't know the internals of spring.net well enough yet so this may not be the most elegant solution but maybe you could change the RemotingConfigurer Filename property to:



/// <summary>
/// Gets or sets the name of the remoting configurationn file.
/// </summary>
/// <remarks>
/// If filename is <see langword="null"/> or not set,
/// default remoting configuration will be used.
/// </remarks>
public string Filename
{
get { return _filename; }
set { _filename = value == null ? null : new FileSystemResource(_filename).File.FullName; }
}
}


I'm afraid I don't know whether this has an impact on other things as well but it works for me so far :)

Oz

oz_ko
10-25-2006, 06:53 AM
/// <summary>
/// Gets or sets the name of the remoting configurationn file.
/// </summary>
/// <remarks>
/// If filename is <see langword="null"/> or not set,
/// default remoting configuration will be used.
/// </remarks>
public string Filename
{
get { return _filename; }
set { _filename = value == null ? null : new FileSystemResource(_filename).File.FullName; }
}

oz_ko
10-26-2006, 04:46 AM
Long day fighting against the machine


/// <summary>
/// Gets or sets the name of the remoting configurationn file.
/// </summary>
/// <remarks>
/// If filename is <see langword="null"/> or not set,
/// default remoting configuration will be used.
/// </remarks>
public string Filename
{
get { return _filename; }
set { _filename = value == null ? null : new FileSystemResource(value).File.FullName; }
}

oz_ko
10-26-2006, 07:32 AM
I didn't think my approach was such a great idea, but you know time constraints etc.

Anyway, after hunting through the code for a while I came up with another solution though it is a little more verbose it doesn't require hacking the spring code (naughty).



<object type="Spring.Remoting.RemotingConfigurer, Spring.Services">
<property name="Filename">
<object type="Spring.Objects.Factory.Config.PropertyRetrievingFa ctoryObject, Spring.Core">
<property name="TargetObject" ref="fileNameResolver" />
<property name="TargetProperty" value="File.FullName" />
</object>
</property>
</object>

<object id="fileNameResolver" type="Spring.Core.IO.FileSystemResource, Spring.Core" >
<constructor-arg name="resourceName" value="~/MyService.exe.config"/>
</object>


Anyone have improvements on this?

Oz

Bruno Baia
10-30-2006, 01:30 AM
Hi,

I prefer the first approach :D
Anyway, using FileSystemResource is maybe too much here, but that works for sure, so you can use it for now.

I need to investigate this.
Maybe something specific due to windows service's execution path.
I've created an issue (http://opensource.atlassian.com/projects/spring/browse/SPRNET-384) for that.


Cheers,
Bruno

oz_ko
10-31-2006, 01:22 AM
Thanks again mate,
Oz