.NET Framework Developer Center > .NET Development Forums > .NET Remoting and Runtime Serialization > Implementation of the remoting interface - Pass a param
Ask a questionAsk a question
 

QuestionImplementation of the remoting interface - Pass a param

  • Friday, October 30, 2009 9:38 PMChristopher Pisz Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code

    How do I pass a parameter to the constructor of the implmentation of the remoting interface?

    I see that you make an interface, then you implement it, and then I see the following: 

    Hashtable properties = new Hashtable();
             properties.Add("port", m_remotingPort);
             BinaryServerFormatterSinkProvider remotingProvider = new BinaryServerFormatterSinkProvider();
             TcpChannel channel = new TcpChannel(properties, null, remotingProvider);
             ChannelServices.RegisterChannel(channel, false);
             RemotingConfiguration.RegisterWellKnownServiceType(GetType(OnlineCourseRemotingImpl), "DataService", WellKnownObjectMode.SingleCall);
    
    

    OnlineCourseRemotingImpl isn't instantiated by me, so I don't know how to pass it say a connection string, since it will need it to perform its database operations. I don't really want to move it down to the libraries app.config, because I have several services that will share the same connection string and want to pass it from the service itself.

    I am new to .NET, hope I made sense.

All Replies

  • Tuesday, November 10, 2009 8:34 PMThomas.W. Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    If I understand correct you want to make the object OnlineCourseRemotingImpl available by remoting to your client and the object is created on the server.
    In that case you may register the object by using RemotingServices.Marshal(...)

    View this example at MSDN:
    http://msdn.microsoft.com/en-us/library/system.runtime.remoting.services.trackingservices.aspx

    If you want the object to live forever you can override the following in the remoteing object:

    public override object InitializeLifetimeService()
    {
        return null;
    }

  • Thursday, November 12, 2009 3:45 AMSmedis Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Something isn't right in that example. If I first run the server and then the client, the server throws exceptions:

    "A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
    Additional information: An existing connection was forcibly closed by the remote host"

    It doesn't seem like the client is disconnecting properly. (I'm under the assumption that there should be no exceptions thrown when a program is written properly...)
    Since this exception is thrown from a worker thread, it's not so simple as a missing try/catch in the server code.

    What is missing from the MSDN example to let the client disconnect gracefully?