Pergunta

I have a singleton service on remote server, this has a method who returns new objects to clients:

public class MySingleton : MarshalByRefObject
{
   public override object InitializeLifetimeService()
   {
      return null;
   }

   public MarshalByRefObject GetService()
   {
      return new Model();
   }
}

public class Model : MarshalByRefObject
{
}

I don't want that Model instances live forever on server, so I just wanted to use the normal sponsorship procedure, on client side I create a sponsor for my Model, and I attach the remote lease to this sponsor:

var sponsor = new ClientSponsor();
_service = _mySingleton.GetService();
var success = sponsor.Register(_service);

Well, this does not work. The remote object Model, dies after a while.

Do you confirm this behavior ?

I guess it's because the lifetime manager on server doesn't have the opportunity to initialize the lease, because the object Model is instanced and returned directly.

Foi útil?

Solução

I know this is an old post but during my search for an similar issue I stumbled on this post.

Maybe it will depend on the SinkProvider configuration. Because the Renewal call on Client side from server require an deserialization. In the app.exe.config on server side you have to setup the serverProvider and also the clientProvider like this:

<channel ref="tcp" port="50220" useIpAddress="false">
 <serverProviders>
  <formatter ref="binary" typeFilterLevel="Full" />
 </serverProviders>
 <clientProviders>
  <formatter ref="binary" />
 </clientProviders>
</channel>
<channel ref="http" port="50221" useIpAddress="false">
 <serverProviders>
  <formatter ref="soap" typeFilterLevel="Full" />
 </serverProviders>
 <clientProviders>
  <formatter ref="soap" />
 </clientProviders>
</channel>

On the client side use the following app.config.exe:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.runtime.remoting>
    <application>
      <channels>
        <channel ref="tcp" port="0">
          <serverProviders>
            <formatter ref="binary" typeFilterLevel="Full"/>
          </serverProviders>
        </channel>
      </channels>
    </application>
  </system.runtime.remoting>
</configuration>
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top