Click here to Skip to main content
15,881,898 members
Home / Discussions / C#
   

C#

 
GeneralRe: Internet downloading problem... Pin
Kentamanos14-Jan-04 9:05
Kentamanos14-Jan-04 9:05 
Generalremoting "newbie" questions Pin
Palladino14-Jan-04 2:24
Palladino14-Jan-04 2:24 
GeneralRe: remoting "newbie" questions Pin
LongRange.Shooter14-Jan-04 3:07
LongRange.Shooter14-Jan-04 3:07 
GeneralRe: remoting "newbie" questions Pin
LongRange.Shooter14-Jan-04 3:23
LongRange.Shooter14-Jan-04 3:23 
GeneralRe: remoting "newbie" questions Pin
Palladino14-Jan-04 8:13
Palladino14-Jan-04 8:13 
GeneralRe: remoting "newbie" questions Pin
LongRange.Shooter14-Jan-04 10:46
LongRange.Shooter14-Jan-04 10:46 
GeneralRe: remoting "newbie" questions Pin
Palladino15-Jan-04 1:36
Palladino15-Jan-04 1:36 
GeneralRe: remoting "newbie" questions Pin
LongRange.Shooter15-Jan-04 2:55
LongRange.Shooter15-Jan-04 2:55 
Pallidino said:
Confused | :confused: Confused | :confused: Confused | :confused:


Michael responds:

Here is what I did that worked and is very simple:

C#
using System.Runtime.Remoting;
using System.Collections;

[Serializable]
public class WidgetCollection:CollectionBase
{
   /// <summary>
   /// Allows indexed access of the Widget item collection
   /// </summary>
   public WidgetItem this[int index]
   {
  get{return (WidgetItem)this.List[index]; }
  set{this.List[index] = value; }
   }
   ///<summary>
   ///  Required Add() method def
   ///</summary>
   public void Add(WidgetItem item)
     {List.Add(item)}
   ///<summary>
   ///  Strong typed key access
   ///</summary>
   public WidgetItem this(string key)
     {return (WidgetItem) List(key)}
 }

 [Serializable]
 public class WidgetItem
 {
      Sprocket internalSprocket
      Spoke    internalSpoke
      DooHickey internalDooHickey
      //public accessors....
      ...
 }


This construct is used by both the client and server objects.

Server creates the WidgetCollection and populates it with Widgets.
Both the WidgetCollection and the Widget are marked [Serializable].

So your server object could be like this assuming that you had a server object instance named Server that handled the population of the WidgetCollection, and you already created the Interface object that defines your WidgetManager for your client use:

C#
public class WidgetManager:MarshalByRefObject, IWidgetManager
{
   public Widget GetWidget(WidgetKey item)
   {
      WidgetCollection itemList = Server.PopulateWidgets();
      return itemList[item];
   }
}


Now.....if you do this, run your remote objects, and get an error that says that {some object} cannot be serialized D'Oh! | :doh: , then {some object} has not been marked [Serializable].

In my example, WidgetItem uses a unique object type of Sprocket, Spoke, and DooHickey. I must make certain that all three object type definitions are marked as [Serializable]. You must keep iterating through your object tree until you finally succeed without the 'cannot be serialized' error. So I'm required to add:

C#
[Serializable]
public class Sprocket()
{
    ...existing definition
}
[Serializable]
public class Spoke()
{
    ...existing definition
}
[Serializable]
public class DooHickey()
{
    ...existing definition
}



The advantage of this approach.....

You can construct your client and use the remote object as a local object while developing and testing without any serialization occuring.
Once you are ready to make the move, you change the local object to a MarshalByRefObject object and mark the objects being returned as [Serializable] and your client use is almost identical with the exception of how the objects are initialized.

We established the standard that if you have objects that are local and MIGHT become remote, that the object initialization be isolated in a method. That way all remote objects are isolated and easy to change from new Object to Activator.GetObject() with the beginning of the method altered to first initialize the channel.

Voila, remoting at it's simplest.

_____________________________________________
Of all the senses I could possibly lose,
It is most often the one called 'common' that gets lost.

GeneralRe: remoting &quot;newbie&quot; questions Pin
LongRange.Shooter15-Jan-04 3:24
LongRange.Shooter15-Jan-04 3:24 
GeneralRe: remoting &quot;newbie&quot; questions Pin
Palladino15-Jan-04 5:43
Palladino15-Jan-04 5:43 
GeneralDebugging Pin
jyoti doiphode13-Jan-04 23:58
jyoti doiphode13-Jan-04 23:58 
GeneralRe: Debugging Pin
Heath Stewart14-Jan-04 4:41
protectorHeath Stewart14-Jan-04 4:41 
GeneralFinding names of local user accounts Pin
EnkelIk13-Jan-04 23:46
EnkelIk13-Jan-04 23:46 
GeneralRe: Finding names of local user accounts Pin
Mazdak14-Jan-04 2:51
Mazdak14-Jan-04 2:51 
GeneralRe: Finding names of local user accounts Pin
EnkelIk14-Jan-04 4:54
EnkelIk14-Jan-04 4:54 
GeneralRe: Finding names of local user accounts Pin
Mazdak14-Jan-04 8:20
Mazdak14-Jan-04 8:20 
GeneralReversible Frames on Windows Forms Pin
occcy13-Jan-04 22:22
occcy13-Jan-04 22:22 
GeneralRe: Reversible Frames on Windows Forms Pin
Heath Stewart14-Jan-04 4:14
protectorHeath Stewart14-Jan-04 4:14 
QuestionHow use Ms treeView In asp.net Pin
Old Gun13-Jan-04 22:03
Old Gun13-Jan-04 22:03 
AnswerRe: How use Ms treeView In asp.net Pin
Heath Stewart14-Jan-04 4:04
protectorHeath Stewart14-Jan-04 4:04 
GeneralRe: How use Ms treeView In asp.net Pin
Not Active14-Jan-04 7:02
mentorNot Active14-Jan-04 7:02 
Generalsharing internet offline files Pin
Mohamad Al Husseiny13-Jan-04 18:18
Mohamad Al Husseiny13-Jan-04 18:18 
GeneralRe: sharing internet offline files Pin
Heath Stewart14-Jan-04 4:02
protectorHeath Stewart14-Jan-04 4:02 
GeneralRe: sharing internet offline files Pin
Mohamad Al Husseiny14-Jan-04 19:20
Mohamad Al Husseiny14-Jan-04 19:20 
GeneralGraph classes for C# Pin
crushinghellhammer13-Jan-04 13:50
crushinghellhammer13-Jan-04 13:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.