Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Trying to update my GUI from remote object but getting Exception

Mike_bgMike_bg Posts: 2Member
I'm trying to make some basic chat client/server application using .net remoting.
I want to make windows form client application and console server application as separate .exe files. Here im trying to call server function AddUser from client and i want to AddUser function update my GUI (richtexbox). When i try to do that i get exception: "[italic]SerializationException: Type Topic in Assembly is not marked as serializable[/italic]".

This will work if i use string variable instead of GUI RichTextBox control which im trying to update from another thread. Im begginer with .net remoting and any suggestion how ti fix this is welcome.

Ill post my client/server code bellow...

Thanks.

[b]SERVER code:[/b]

[code]namespace Test
{
public class Topic : MarshalByRefObject
{
[b]public bool AddUser(string user,RichTextBox textBox1,List listBox1)
{
//Send to message only to the client connected
MethodInvoker action = delegate { textBox1.Text += "Connected to
server...
"; };
textBox1.BeginInvoke(action);
//...
return true;
}[/b]

public class TheServer
{
public static void Main()
{

int listeningChannel = 1099;

BinaryServerFormatterSinkProvider srvFormatter = new
BinaryServerFormatterSinkProvider();
srvFormatter.TypeFilterLevel = TypeFilterLevel.Full;

BinaryClientFormatterSinkProvider clntFormatter = new
BinaryClientFormatterSinkProvider();

IDictionary props = new Hashtable();
props["port"] = listeningChannel;

HttpChannel channel = new HttpChannel(props, clntFormatter,
srvFormatter);
// Register the channel with the runtime
ChannelServices.RegisterChannel(channel, false);
// Expose the Calculator Object from this Server
RemotingConfiguration.RegisterWellKnownServiceType(typeof
(Topic),
"Topic.soap",
WellKnownObjectMode.
Singleton);
// Keep the Server running until the user presses enter
Console.WriteLine("The Topic Server is up and running on port
{0}", listeningChannel);
Console.WriteLine("Press enter to stop the server...");
Console.ReadLine();
}
}
}
}[/code]

[b]CLIENT CODE:[/b]

[code]// Create and register a channel to communicate to the server
// The Client will use the port passed in as args to listen for
callbacks

private Topic topic;

BinaryServerFormatterSinkProvider srvFormatter = new
BinaryServerFormatterSinkProvider();
srvFormatter.TypeFilterLevel = TypeFilterLevel.Full;
BinaryClientFormatterSinkProvider clntFormatter = new
BinaryClientFormatterSinkProvider();
IDictionary props = new Hashtable();
props["port"] = 0;

channel = new HttpChannel(props, clntFormatter, srvFormatter);
//channel = new HttpChannel(listeningChannel);

ChannelServices.RegisterChannel(channel, false);
// Create an instance on the remote server and call a method remotely
topic = (Topic)Activator.GetObject(typeof(Topic), // type to create
"http://localhost:1099/Topic.soap" // URI
);


[b]public RichTextBox textbox1;
bool check = topic.addUser(textBoxNickname.Text,textBox1, [/b]listitems);[/code]

Comments

Sign In or Register to comment.