ServicesResourcesConferences Our TeamWeblogsAboutContact
     
  

Developer Resources

  Architecture Briefings
  Articles
  Conversations
  Tools and Samples
  Books

HOWTO: Publish a specific object-instance via Remoting

Question

How can I publish a certain object's instance? The reason I want to do this, is that I want to pass parameters using the object's constructor during server-startup.

i.e.

SomeObject obj = new SomeObject("Hello World");

// and now do-some-magic and publish this object 
// at http://localhost:1234/thisobject.soap

When a client now contacts http://localhost:1234/thisobject.soap, the call should be answered from this exact instance.

Answer

You can use RemotingServices.Marshal() to publish a specific instance.

The following piece of code will do exactly what you described in your question:

HttpChannel channel = new HttpChannel( 1234 ); 
ChannelServices.RegisterChannel( channel ); 

SomeObject obj = new SomeObject("Hello World"); 
RemotingServices.Marshal(obj,"thisobject.soap");

And by the way, if you want your object to live forever, don't forget to override InitializeLifetimeService() to return a "null" which means indefinite lifetime!

public class SomeObject : MarshalByRefObject 
{
  public override Object InitializeLifetimeService()
  {
    return null;
  }
} 





 

© 2002-2006 by Thinktecture, Ingo Rammer and Christian Weyer. All rights reserved. | Contact | Impressum