PDA

View Full Version : OpenSessionInView + remoting?


bwhelan
04-26-2007, 04:25 PM
Hi,

I'm running up against a brick wall trying to figure out how to do this, if it is possible, or if I am doing it the right way. I'd be glad of any help.

I have a web app using Spring.NET, and the NHibernate 1.2 beta module. I have it all working when all the tiers are hosted on the same server. Now, I want to split the tiers onto a web server and a second server for the business services and database. Basically, all the NHibernate work will be done on the new app server and the services exported via remoting. So i think the only module that needs to be configured on the web server is the OpenSessionInViewModule.

Now here is the catch: I can't get OpenSessionInViewModule to work over remoting and can't find any examples of someone who has done this. OSIV needs a SessionFactory instance, but that is configured with all the other Spring NHibernate components on the business logic server. Can an instance of the Spring LocalSessionFactoryObject be remoted to the web server (i.e. is declared as a MarshalByRefObject)? Currently it is giving me a RemotingException (no detail reported). Maybe I have the remoting configuration wrong for the SessionFactory. Or should I be looking at a different way? I'd be interested how other people have managed to do this.

Here's the relevant portions of config:

Web.Config:

<httpModules>
<add name="Spring" type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
<add name="OpenSessionInView" type="Spring.Data.NHibernate.Support.OpenSessionInViewMo dule, Spring.Data.NHibernate12"/>
</httpModules>

<appSettings>
<add key="Spring.Data.NHibernate.Support.OpenSessionInViewMo dule.SessionFactoryObjectName" value="SessionFactory" />
</appSettings>

Client Services xml config file:

<objects xmlns="http://www.springframework.net" xmlns:r="http://www.springframework.net/remoting">
<r:caoFactory id="SessionFactory" remoteTargetName="SessionFactory" serviceUrl="tcp://mongol:8005" />
<r:caoFactory id="GenericService" remoteTargetName="GenericService" serviceUrl="tcp://mongol:8005" />
</objects>

Services xml config file on Business Logic Server:

<objects xmlns="http://www.springframework.net" xmlns:r="http://www.springframework.net/remoting">
<r:caoExporter targetName="SessionFactory" infinite="false">
<r:lifeTime initialLeaseTime="2m" renewOnCallTime="1m" />
</r:caoExporter>
<r:caoExporter targetName="GenericService" infinite="false">
<r:lifeTime initialLeaseTime="2m" renewOnCallTime="1m" />
</r:caoExporter>

<object id="SessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate12">
<property name="DbProvider" ref="DbProvider"/>
<property name="MappingAssemblies">
<list>
<value>Domain.Persistence.NHibernate</value>
</list>
</property>
<property name="HibernateProperties">
<dictionary>
<entry key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
<entry key="hibernate.dialect" value="NHibernate.Dialect.MySQL5Dialect"/>
<entry key="hibernate.connection.driver" value="NHibernate.Driver.MySqlDataDriver"/>
</dictionary>
</property>
</object>
</objects>

Bruno Baia
04-26-2007, 04:33 PM
Hi,

Have you configured the remoting infrastructure on the server ?

<system.runtime.remoting>
<application>
<channels>
<channel ref="tcp" port="8005" />
</channels>
</application>
</system.runtime.remoting>


<r:configurer filename="MyApplication.exe.config" />

Or by the code using RemotingConfiguration.Configure method.


- Bruno

bwhelan
04-27-2007, 12:59 PM
Hi Bruno,

I was missing the remoting channel configuration on the client. I have the remoting channel working fine now - I can injection one of my business services into a page and call it with no problems (except for a lazy load session closed exception due to the disabled OSIV module).

I still can't get the remote SessionFactory to work with the OSIV. When I enable the web.config line to add the OSIV module, it gives me an exception:

[ArgumentNullException: Argument 'Key must not be null' cannot be null.
Parameter name: Key must not be null]
Spring.Util.AssertUtils.ArgumentNotNull(Object argument, String name) +159
Spring.Transaction.Support.TransactionSynchronizat ionManager.HasResource(Object key) +34
Spring.Data.NHibernate.Support.OpenSessionInViewMo dule.Open() +80
Spring.Data.NHibernate.Support.OpenSessionInViewMo dule.context_BeginRequest(Object sender, EventArgs e) +29
System.Web.SyncEventExecutionStep.System.Web.HttpA pplication.IExecutionStep.Execute() +92
System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean& completedSynchronously) +64

Maybe the exception is because the remote SessionFactory object is null somehow (or can not be cast in the correct type)?

Server:

<object id="SessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate12" singleton="true">
[...]
</object>

<r:caoExporter targetName="SessionFactory" infinite="false">
<r:lifeTime initialLeaseTime="2m" renewOnCallTime="1m"/>
</r:caoExporter>


Client:

<appSettings>
<add key="Spring.Data.NHibernate.Support.OpenSessionInViewMo dule.SessionFactoryObjectName" value="SessionFactory" />
</appSettings>

<r:caoFactory id="SessionFactory" remoteTargetName="SessionFactory" serviceUrl="tcp://mongol:8005" />

Is this the right way to remote the SessionFactory? I've tried SAO, but same error.

Bren.