Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

.net Remoting Question

Posted on 2006-07-15
6
Medium Priority
?
800 Views
Last Modified: 2010-08-05
I just read the remoting documentation for .net 2.0 for IpcServerChannel/IpcClientChannel.  I see that the client accesses an object that exists in the memory of the server.  Is there any way for the server to access this object as well, or does the host just hold objects that are modified by the different clients?
0
Comment
Question by:kayhustle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 7

Expert Comment

by:whatsit2002
ID: 17116547
Yes, just because an object is remotable doesn't mean you have to access it remotely. The server has full access to the object it is hosting. A typical configuration would look something like this:

Server:
Remoteable Object
Host Service / Application (in charge of hosting the remoted object)

Client:
Client application to access remote object
Object Interface (the interface the client will use to access the remote object)

You can put the remoted object in the GAC on the server. Then, any app on the server can access it including your host service.

Thanks.

Jason
0
 
LVL 1

Author Comment

by:kayhustle
ID: 17117469
Ok, can you show me an example of how I would access the remoted object from the server?
0
 
LVL 7

Expert Comment

by:whatsit2002
ID: 17117492
Since the object is sitting on the server, applications on the server can make direct references to it. Simply add a reference to the object in your project and instanciate it like any other class:

You have the three following items:
1) Host Service and remoteable object (on server)
2) Client application accessing the object remotely (on workstation)
3) Server application accessing the object locally (on server)

Steps to reference the object locally from the server application:
1) Add reference to project (right-click references in solution explorer and choose "Add Reference...")
2) Instanciate the object (ex: MyRemotedObject mro = new MyRemotedObject()) and make use of it.
3) Assuming your object is in the GAC on the server (since you already have it set up for remoting), the only thing left is to deploy your app and it will find the object in the GAC... no need to deploy the object in your app's folder.

One caveat is that if you want your app on the server to use the same instance as the clients accessing it remotely (i.e. a singleton object) then you should access it remotely from the server as if your app was sitting on a workstation. Just set up your server app the same way you did your client app.

Jason
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
LVL 1

Author Comment

by:kayhustle
ID: 17117537
If I call RemotingConfiguration.RegisterWellKnownClientType in the server after having called RemotingConfiguration.RegisterWellKnownServiceType on the same type I get an exception saying that it has already been registered.  If I instantiate an instance of the class inside my server code, it will not be the same object as the one accessible to the clients.  Here is a code sample of my server:

public static void Main()
    {
        IDictionary properties = new Hashtable();
        properties.Add("portName", "remote");
        properties.Add("secure", true);
        properties.Add("impersonate", true);
        // Create and register an IPC channel
        IpcServerChannel serverChannel = new IpcServerChannel(properties,null);
        ChannelServices.RegisterChannel(serverChannel,false);

        // Expose an object
        RemotingConfiguration.RegisterWellKnownServiceType(typeof(Counter), "counter", WellKnownObjectMode.Singleton);
        //The client is not accessing the same Counter that was just declared here
        Counter c = new Counter();
        c.text = "YO YO YO YO!";
       
        Console.WriteLine("Listening on {0}", serverChannel.GetChannelUri());
        ThreadPool.QueueUserWorkItem(new WaitCallback(go));
        Console.ReadLine();
    }
    private static void go(object o)
    {
        IDictionary properties = new Hashtable();
        properties.Add("secure", true);
        properties.Add("connectionTimeout", 5000);
        properties.Add("tokenImpersonationLevel", "Impersonation");


        IpcClientChannel clientChannel = new IpcClientChannel(properties, null);
        ChannelServices.RegisterChannel(clientChannel,false);
       
        //this line throws an exception if run
        RemotingConfiguration.RegisterWellKnownClientType(typeof(Counter), "ipc://remote/counter");
       
        //This counter is not the same as the previous counter that was declared in the main function.  It's text is blank
        Counter counter = new Counter();
        Console.WriteLine("text is " + counter.text);
        Console.WriteLine("This is call number {0}.", counter.Count);
        counter.text = "Time is: " + DateTime.Now.ToLongTimeString();
        ThreadPool.QueueUserWorkItem(new WaitCallback(checktext));
        Console.ReadLine();
    }
    private static void checktext(object o)
    {
        Counter counter = new Counter();
        while (true)
        {
            Console.WriteLine("Text is now: " + counter.text);
            System.Threading.Thread.Sleep(2000);
        }
    }
0
 
LVL 7

Accepted Solution

by:
whatsit2002 earned 2000 total points
ID: 17117994
Ok, now I know what you're talking about. Sorry, I should have cleared a couple things up earlier. I didn't realize you were trying to use the same instance that the clients were using with a Singleton object.

To create an instance of the remote object locally on the server, try this:

Counter RObj = (Counter)Activator.GetObject(typeof(Counter), "ipc://remote/counter");

Hope that helps.

Thanks

Jason
0
 
LVL 1

Author Comment

by:kayhustle
ID: 17118125
Ok, that works, thanks.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question