Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Leasing and sponsoring .net

Leasing and sponsoring .net

Scheduled Pinned Locked Moved .NET (Core and Framework)
csharpdotnethelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    seconds87
    wrote on last edited by
    #1

    Hi, Nowaday I'm working on .net remoting and I've got some problem with leasing. there is my code:

    //RemoteObject
    public class X : MarshalByRefObject
    {
    public int x;
    public X()
    {
    Console.WriteLine("some X object is done...");
    }
    public void PrintAboutMe()
    {
    ILease itfILease = (ILease)RemotingServices.GetLifetimeService(this);
    Console.WriteLine("CurrentState: " + itfILease.CurrentState);
    Console.WriteLine("InitialLeaseTime: " + itfILease.InitialLeaseTime.Minutes +
    ":" + itfILease.InitialLeaseTime.Seconds);
    Console.WriteLine("CurrentLeaseTime: " + itfILease.CurrentLeaseTime.Minutes +
    ":" + itfILease.CurrentLeaseTime.Seconds);
    Console.WriteLine("RenewOnCallTime: " + itfILease.RenewOnCallTime.Minutes +
    ":" + itfILease.RenewOnCallTime.Seconds);
    Console.WriteLine("SponsorShipTime: " + itfILease.SponsorshipTimeout.Minutes +
    ":" + itfILease.SponsorshipTimeout.Seconds);
    Console.WriteLine("x = " + x);
    }
    public override object InitializeLifetimeService()
    {
    ILease itfLease = (ILease)base.InitializeLifetimeService();
    if (itfLease.CurrentState == LeaseState.Initial)
    {
    itfLease.InitialLeaseTime = TimeSpan.FromSeconds(10);
    itfLease.RenewOnCallTime = TimeSpan.FromSeconds(6);
    itfLease.SponsorshipTimeout = TimeSpan.FromSeconds(6);
    }
    // return null;
    return itfLease;
    }
    public void IncrementX()
    {
    x++;
    Console.WriteLine("\nIncrement x member ...\n");
    }
    public void ChangeLifetime()
    {
    ILease itfILease = (ILease)RemotingServices.GetLifetimeService(this);
    itfILease.Renew(TimeSpan.FromSeconds(20));
    }
    }
    //SponsorObjectCode
    public class MySponsor : MarshalByRefObject, ISponsor
    {
    public TimeSpan Renewal(ILease il)
    {
    Console.WriteLine("I've been asked to renew the lease.");
    return TimeSpan.FromSeconds(20);
    }
    }

    //ClientCode:
    public static void Main(string[] args)
    {
    HttpChannel c = new HttpChannel(null,
    new BinaryClientFormatterSinkProvider(),
    null);
    ChannelServices.RegisterCh

    J 1 Reply Last reply
    0
    • S seconds87

      Hi, Nowaday I'm working on .net remoting and I've got some problem with leasing. there is my code:

      //RemoteObject
      public class X : MarshalByRefObject
      {
      public int x;
      public X()
      {
      Console.WriteLine("some X object is done...");
      }
      public void PrintAboutMe()
      {
      ILease itfILease = (ILease)RemotingServices.GetLifetimeService(this);
      Console.WriteLine("CurrentState: " + itfILease.CurrentState);
      Console.WriteLine("InitialLeaseTime: " + itfILease.InitialLeaseTime.Minutes +
      ":" + itfILease.InitialLeaseTime.Seconds);
      Console.WriteLine("CurrentLeaseTime: " + itfILease.CurrentLeaseTime.Minutes +
      ":" + itfILease.CurrentLeaseTime.Seconds);
      Console.WriteLine("RenewOnCallTime: " + itfILease.RenewOnCallTime.Minutes +
      ":" + itfILease.RenewOnCallTime.Seconds);
      Console.WriteLine("SponsorShipTime: " + itfILease.SponsorshipTimeout.Minutes +
      ":" + itfILease.SponsorshipTimeout.Seconds);
      Console.WriteLine("x = " + x);
      }
      public override object InitializeLifetimeService()
      {
      ILease itfLease = (ILease)base.InitializeLifetimeService();
      if (itfLease.CurrentState == LeaseState.Initial)
      {
      itfLease.InitialLeaseTime = TimeSpan.FromSeconds(10);
      itfLease.RenewOnCallTime = TimeSpan.FromSeconds(6);
      itfLease.SponsorshipTimeout = TimeSpan.FromSeconds(6);
      }
      // return null;
      return itfLease;
      }
      public void IncrementX()
      {
      x++;
      Console.WriteLine("\nIncrement x member ...\n");
      }
      public void ChangeLifetime()
      {
      ILease itfILease = (ILease)RemotingServices.GetLifetimeService(this);
      itfILease.Renew(TimeSpan.FromSeconds(20));
      }
      }
      //SponsorObjectCode
      public class MySponsor : MarshalByRefObject, ISponsor
      {
      public TimeSpan Renewal(ILease il)
      {
      Console.WriteLine("I've been asked to renew the lease.");
      return TimeSpan.FromSeconds(20);
      }
      }

      //ClientCode:
      public static void Main(string[] args)
      {
      HttpChannel c = new HttpChannel(null,
      new BinaryClientFormatterSinkProvider(),
      null);
      ChannelServices.RegisterCh

      J Offline
      J Offline
      Jack Vanderhorst
      wrote on last edited by
      #2

      For the first question, this code runs fine for me and the lease is being successfully renewed. :wtf: For the second question, you already are, when you run this code the client is interacting with the remote (ie. proxy) object and the actual object exists and is even outputting text onto the Server's console. I haven't done much with remoting, but that's my two cents, hope it helps.

      S 1 Reply Last reply
      0
      • J Jack Vanderhorst

        For the first question, this code runs fine for me and the lease is being successfully renewed. :wtf: For the second question, you already are, when you run this code the client is interacting with the remote (ie. proxy) object and the actual object exists and is even outputting text onto the Server's console. I haven't done much with remoting, but that's my two cents, hope it helps.

        S Offline
        S Offline
        seconds87
        wrote on last edited by
        #3

        I'd like to thank you for help, I found the solution for first problem... I didn't know that: current lease time = MAX(lease time - expired time,renew on call time) source: http://msdn.microsoft.com/en-us/magazine/cc300474.aspx 2. You wrote: "and the actual object exists and is even outputting text onto the Server's console" yes, I know but I'd like to have a reference to this object (I want to communicate with it), this remote object is working fine (object is created and managed by client) but everything is working on "background". I have got a primitive way to comunicate with every object by static class members but it's not exactly what I want to.

        J 1 Reply Last reply
        0
        • S seconds87

          I'd like to thank you for help, I found the solution for first problem... I didn't know that: current lease time = MAX(lease time - expired time,renew on call time) source: http://msdn.microsoft.com/en-us/magazine/cc300474.aspx 2. You wrote: "and the actual object exists and is even outputting text onto the Server's console" yes, I know but I'd like to have a reference to this object (I want to communicate with it), this remote object is working fine (object is created and managed by client) but everything is working on "background". I have got a primitive way to comunicate with every object by static class members but it's not exactly what I want to.

          J Offline
          J Offline
          Jack Vanderhorst
          wrote on last edited by
          #4

          For the first response, neither did I! I just changed the renewed lease time to 5 days so I could easily see it was working. For the second, I agree it sounds less than ideal, but I'm not sure how else you would do it. Maybe your design could change a little? Perhaps the client-side object can quietly "phone home" asychronously for some new info? Perhaps the client-side object could raise an event that you handle on the server?

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups