0

Ok so I know I am very very new to .NET remoting and I have a question as far as best practice goes. First, I already have an in-house application that I have built and have dll's that I reference that handle all of the data for me. I want the Server version of my application to be able to utilize all of those classes and their methods and be able to pass those custom objects back and forth.

My question is, should I, apply [Serializable] to all of my classes that I want to pass back and forth and then create special classes that specifically use my methods to Get, AddOrUpdate, Delete, etc?

Right now, I have Get, AddOrUpdate, and Delete methods in all of my classes that communicate back and forth with my database. I have already learned that I can't MarshalByRefObject & [Serializable] to all of those classes or I will run into issues. So, thats why I am thinking I need to create separate classes that do "Management" (ex. Get, AddOrUpdate, Delete) as opposed to having Property definitions as well as Method calls.

An example of what I am thinking needs to be done.

[Serializable]
    public class Users {
        #region Properties...
        private int _userID;
        private string _displayName;
        private string _userName;
        private string _firstName;
        private string _lastName;
        private string _LogOnPassword;
        private List<Users> _Associates = new List<Users>();
        private AuthenticationLevel _authorizationLevel;
        private string _userSettingsXML;
        private string _active;
        private string _signature;
        private int _PhoneExtension;
        private int _Index;
        private List<UserAssignedRoles> _Roles = new List<UserAssignedRoles>();

Then to actually create a list I would have a separate class called something like UserManagement.

public class UserManagement : MarshalByRefObject { 
    public List<Users> GetUsers() { 

    }
}

Any advice is greatly appreciated!

Steven Combs
  • 1,890
  • 6
  • 29
  • 54
  • See http://msdn.microsoft.com/en-us/library/5dxse167(v=vs.80).aspx and http://www.alexthissen.nl/blogs/main/archive/2007/12/23/back-to-net-remoting-typefilterlevel.aspx You can pass all your objects as MarshalByRefObject if you need, as long as you have enough privileges. All others depend on your design decision. – L.B Feb 13 '12 at 23:10
  • The best practice for Remoting in general is to drop it and move on to WCF. Maybe you're limited to Fx2 or so, but be sure to survey the options. – H H Feb 13 '12 at 23:46
  • Henk, thanks I think I am definitely going the WCF route. Looks like it is going to be a much simpler approach than Remoting and more elegant which is what I am looking for. – Steven Combs Feb 14 '12 at 02:26

1 Answers1

1

Remoting might be a fine approach, but since you didn't give a lot of context as to why you are remoting, let me offer an additional suggestion. You may want to consider creating Web Services for communication across architectural tiers. Windows Communication Foundation (WCF) is a mature technology that makes this pretty straight-forward for simple communication. You may also want to read about Service Oriented Architecture (SOA), perhaps starting with the four SOA tenets.

You should not have any trouble reusing your current classes with WCF. Services will just give you a little better structure, plus WCF skills are far more common than .NET Remoting skills (for the person who needs to manage this code next after you).

Good luck! -Bill

codingoutloud
  • 2,115
  • 19
  • 21
  • Awesome thank you! Yeah I apologize about the lack of information. My application is basically taking on newly requested features. It has been mostly database driven so far and hasn't needed any Server Client infrastructure built into it. I learned a little bit of .NET remoting but I have been curious as to what else is out there. I am actually looking into WCF as we speak. Thank you very much for your links. – Steven Combs Feb 14 '12 at 02:26
  • Bill, I do have a question. I read the articles you provided and thank you those were key pieces of material that I needed to read. I went ahead and created a test Server and Client using my dll and it worked very easily following the tutorial. I noticed that I had to generate the proxy and then incorporate that file into my client. What I dont like is that my client code doesnt follow the elegance of my class design. So my question is, can I retain my class design such as MyDatabase.Orders, MyDatabase.Users, etc in the client code or is that just a sacrifice that needs to be made? – Steven Combs Feb 15 '12 at 16:25
  • You don't need to use the proxy, though that is a simplification that is often handy. If you want to "roll your own" check out this post on codereview.stackexchange.com with some sample code: http://codereview.stackexchange.com/questions/7793/how-to-improve-wcf-client-proxy-based-on-createchannel-not-generated-from-wsdl – codingoutloud Feb 15 '12 at 19:37