0

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

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Leonardo
  • 3,141
  • 3
  • 31
  • 60
  • 1
    are you serializing the data or the form? the data is one thing, that's common. but if you are trying to send the form over the wire.... that's a different story. One that I would avoid. – Jason Meckley Jun 08 '12 at 03:08

2 Answers2

1

You might want to take a look at this project: http://www.codeproject.com/Articles/24508/How-to-Serialize-a-TreeNode-Object

Basically, you can make a wrapper for any class and make it serializable by adding the [Serializable] attribute

[Serializable]
public class MyClass : InheritedClass
{//Your code}
Alex Rose
  • 127
  • 3
  • 10
  • But I'm using a Form, I tried putting [Serializable] but nothing happens. The tutorial inherits from TreeNodeCollection, but in my project I return TreeNodeCollection and ListView, so I'd have to create 2 different classes, which is not a good thing... Any other ideas ? Thanks for helping so far ! – Leonardo Jun 08 '12 at 03:18
1

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;
}
Simon MᶜKenzie
  • 8,344
  • 13
  • 50
  • 77
  • What you mean Simon ? Why at the client side if what I want is to get the files from the server ? I don't get it ! Thanks for the help so far ! – Leonardo Jun 08 '12 at 06:46
  • The list of files comes from the server, so the file list should go from the server to the client via remoting, but the UI elements (i.e. the `TreeNodeCollection`) should be constructed by the client. You don't want to send UI elements via remoting. – Simon MᶜKenzie Jun 08 '12 at 06:56