.NET General

Moderators: None (Apply to moderate this forum)
Number of threads: 797
Number of posts: 1359

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Trying to update my GUI from remote object but getting Exception Posted by Mike_bg on 20 Jul 2009 at 2:33 AM
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: "SerializationException: Type Topic in Assembly is not marked as serializable".

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.

SERVER code:

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

       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();
           }
       }
   }
}


CLIENT 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
       );

   
       public RichTextBox textbox1;
       bool check = topic.addUser(textBoxNickname.Text,textBox1, listitems);

Report
Re: Trying to update my GUI from remote object but getting Exception Posted by DataDink on 20 Jul 2009 at 11:50 AM
A class needs the Serializable attribute on its definition before you can serialize an instantiation of it.

So your "Topic" class needs this attribute...
[Serializable]
public class Topic
{

}



Report
Re: Trying to update my GUI from remote object but getting Exception Posted by Mike_bg on 22 Jul 2009 at 3:04 AM
Topic class supposed to be Marshal By Reference. Marking Topic class as Serializable does not change anything as its already inherited from MarshalByRefObject class. Even if i change still get same error. ;)



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.