[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 299
  • Last Modified:

Remoting timeout

I'm marshalling this ByRef object, and i connect to it from a client.. all goes very well, but when the client disconnects for some minutes, reconnecting results in "cannot find requested service" when calling a method on the ByRef object.  I assume the lifetime of my server-object has expired.  Can i make this infinite? (Code below)

I think my problem would be better resolved using Client-Activated objects, but in that case i have no clue how to make that object communicate with the rest of my service, for instance, to return statistics about what the service is doing.  My problem is that i should be able to get a reference in that client-activated object to any other class in the service but because the object is virtually constructed at client's side, i cannot drop in an argument in the constructor from service-side.  Any help here?

Back to my current plan, here's the code:

Marshalling a MarshalByRef object from a main controller object in the service:

'Open a Tcp channel for communication
Dim aChannel As New TcpChannel(6000)
ChannelServices.RegisterChannel(aChannel)

'Create publishing object and "Marshal" it (= make available to remote processes)
FDataPublisher = New DataPublisher(Me)
RemotingServices.Marshal(FDataPublisher, "DataPublisher.rem")

The MarshalByRef object looks like this (The FDataProvider is the "Me" in previous code-part, and is a main controller object):

Public Class DataPublisher
    Inherits MarshalByRefObject

    Protected FDataProvider As IDataProvider

    Public Sub New(ByVal ADataProvider As IDataProvider)
        FDataProvider = ADataProvider
    End Sub

    Public Function GetData() As Data
        Return FDataProvider.GetData()
    End Function

   ' blabla, some more functions that return or change data

End Class

And finally, my client connects like this in the "Load" eventhandler of the mainform:

Dim InfoPublisher As Object = Activator.GetObject(GetType(DataPublisher), "tcp://localhost:6000/DataPublisher.rem")
FDataPublisher = CType(InfoPublisher, DataPublisher)

The crash occurs when not having used the service for some time, and then launching the client again and requesting a remote-method again.  Like this:

Dim myData As Data = FDataPublisher.GetData()

thank you,

Thomas
0
IT Meetjesland
Asked:
IT Meetjesland
1 Solution
 
Jens FiedererCommented:
Defining

    Public Overrides Function InitializeLifetimeService() As Object
        Return Nothing
    End Function

In your MarshalByRefObject gives it an infinite lifetime.
0
 
IT MeetjeslandAuthor Commented:
easy money :)
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now