-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: Nhibernate and Services
PostPosted: Tue Sep 06, 2005 1:35 pm 
Beginner
Beginner

Joined: Tue May 17, 2005 11:42 am
Posts: 22
I


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 08, 2005 1:10 pm 
Beginner
Beginner

Joined: Tue May 17, 2005 11:42 am
Posts: 22
Also, if i try to instantiate a SessionFactory and transfer it via remoting I get this exception.
Code:
The object with ID 2 implements the IObjectReference interface for which all dependencies cannot be resolved. The likely cause is two instances of IObjectReference that have a mutual dependency on each other.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 09, 2005 12:14 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
I don't know if it is related to your problem, but your ApplicationServer shouldn't be [Serializable].

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 09, 2005 1:47 pm 
Beginner
Beginner

Joined: Tue May 17, 2005 11:42 am
Posts: 22
I tried removing the [Serializable] attribute from the ApplicationServer, but it still throws the same exception. :cry:

What I need to know is how should I plug Nhibernate with .NET Remoting so that the Broker can be serialized and know a SessionFactory to be able to repair the session.

The client needs to obtain the ApplicationServer via remoting (service layer) and invoke the method ApplicationServer.CreateBOBroker();
Code:
public BOBroker CreateBOBroker()
  {
    return (new BOBroker(this.SessionFactory));
  }


In order to be able to repair the Nhibernate Session the BOBroker needs the SessionFactory.
My BOBroker is a class that wraps the behaviour of ISession and adds other business logic.
Code:
public void OpenSession()
  {
    this.Session = this.SessionFactory.OpenSession();
  }

  public void CloseSession()
  {
    this.Session.Close();
  }

  public void RepairSession()
  {
    this.CloseSession();
    this.OpenSession();
  }

Any ideas, are welcome. :D
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 10, 2005 9:27 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
I have:

Code:
public sealed class DataPortal : System.MarshalByRefObject
{
   public void Open/CloseSession() + CRUD methods
}


On the server side, I do:
Code:
// Register TcpChannel
try
{
   System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(
      new System.Runtime.Remoting.Channels.Tcp.TcpChannel(Settings.Port) );
}
catch
{
   log.Info("Close Application - Already running (the TcpChannel:" + Settings.Port + " is not available) !");
   return;
}


// Set up Remoting Configuration + Register Service
try
{
   System.Runtime.Remoting.RemotingConfiguration.ApplicationName = "XXX.Server";
   System.Runtime.Remoting.RemotingConfiguration.Configure(System.Runtime.Remoting.RemotingConfiguration.ApplicationName + ".exe.config");
            logBuilder.Append("CustomErrors Enabled ForRemoteCallers = " + System.Runtime.Remoting.RemotingConfiguration.CustomErrorsEnabled(false).ToString() + System.Environment.NewLine);
   System.Runtime.Remoting.RemotingConfiguration.RegisterWellKnownServiceType(
      typeof(DataPortal), "DataPortalUri",
      System.Runtime.Remoting.WellKnownObjectMode.SingleCall);
}



And on the client side:
Code:
try
{
   System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient(this._appSettings.ServerName, this._appSettings.ServerPort);
   // If the TcpClient can be build => the RemoteServer is accessible, so we can register...
   client.Close();
   System.Runtime.Remoting.RemotingConfiguration.Configure(null);
   System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(
      new System.Runtime.Remoting.Channels.Tcp.TcpChannel() );
   System.Runtime.Remoting.RemotingConfiguration.RegisterWellKnownClientType(
      typeof(DataPortal),
      "tcp://" + this._appSettings.ServerName + ":" + this._appSettings.ServerPort.ToString() + "/Kresus.Server/DataPortalUri");
   log.Info(string.Format("Use the RemoteServer - {0}:{1}", this._appSettings.ServerName, this._appSettings.ServerPort));
}
catch
{
   // => The app will create the DataPortal locally
   log.Warn(string.Format("Don't use RemoteServer ({0}:{1}) => Try to access directly to the Database...", this._appSettings.ServerName, this._appSettings.ServerPort));
}

// Initialize the DataPortal
_myLocalDataPortal = new DataPortal(); // Here, .NET will set a reference to the remote dataportal :)

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 10, 2005 9:47 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Note that NHibernate SessionFactory and Sessions are completly hidden behind this DataPortal; so I don't know if it will correctly work if you access them...

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 11, 2005 4:50 pm 
Knight
your metod is wrong.
you need to transfer th Isession with the marshalbyvalue object.

correct one is KPixel's metod.


Top
  
 
 Post subject:
PostPosted: Mon Sep 12, 2005 10:52 am 
Beginner
Beginner

Joined: Tue May 17, 2005 11:42 am
Posts: 22
Thanks Kpixel for posting your code, it let me acknowledge where the problem was.

In your solution DataPortal behaves almost like my BOBroker, but in my solution ApplicationServer is important because it handles the configuration the brokers need to work on the client side. (Have in mind this is a Windows Forms Application). The main difference between our codes is that I need to expose ApplicationServer via remoting on the client side instead of BOBroker (DataPortal).

With this kind scenario I believe there are basically two options:

    1. Wrapping the SessionFactory and Session inside an object that handles open/close/repair and CRUD operations, this object should be the one published via remoting.
    2. On the other hand you might want to load the configuration on the Server side and then configure each client based on this one.
    This solution would require something like a SessionWrapperObjectFactory that should be based uppon the Server


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.