Search code examples
c#.netwinformsremoting

Serializing Form in C# using Remoting


Well, first of all, I've been looking at the internet for over 2 hours now but I couldn't really find any useful answer to my problem. Well, its quite simple: I have a Client-Server program which I need to list the files in a server using Remoting and Form (I know about WCF, but that's not the point here). Well, I have all the listing directory/folders working ok (testing without Remoting, in my own PC), but when I tried to "Remote" this, I'm having a hard time.

First of all: I'm using http as channel and the registering and activation is all right. At least I guess, as I'm using:

RemotingServices.Marshal(Server,"ListaArquivos")

in the server and

server = (Server)Activator.GetObject(typeof(ServerDLL.Server), "http://localhost:12345/ListaArquivos")

in the client, where Server is the .dll (MarshalByRefObject).

My steps are:

  1. I have the .dll class (inherits MarshalByRefObject) which holds all the methods that I call in the client-to-server steps. 1 of this methods returns a TreeNodeCollection and...
  2. In the client Form, I call this method and I try to insert this Collection into the Form, but that's when I get the "Windows.Form.TreeNodeCollection" blabla "not serializable".

And that's my doubt, how can I make this work ? P.S-> My project link: My Explorer


Solution

  • If all you want is a list of archives, you should be sending only the list of files, most likely as a string array. Your TreeNodeCollection should be constructed on the client side from that list.

    If you need to send more information than a simple string array (i.e. you need a tree structure), define a simple datatype for sending the information:

    [Serializable]
    class Node
    {
        public string Name;
        public Node[] Children;
    }