简体   繁体   English

C#.NET远程处理最佳实践?

[英]C# .NET Remoting Best Practice?

Ok so I know I am very very new to .NET remoting and I have a question as far as best practice goes. 好的,所以我知道我对.NET远程处理非常陌生,就最佳实践而言,我还有一个问题。 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. 首先,我已经拥有一个内部应用程序,该应用程序已经构建并且具有我引用的dll,可以为我处理所有数据。 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? 我的问题是,是否应该将[Serializable]应用于我想来回传递的所有类,然后创建专门使用我的方法进行Get,AddOrUpdate,Delete等的特殊类?

Right now, I have Get, AddOrUpdate, and Delete methods in all of my classes that communicate back and forth with my database. 现在,我所有与数据库进行来回通信的类中都有Get,AddOrUpdate和Delete方法。 I have already learned that I can't MarshalByRefObject & [Serializable] to all of those classes or I will run into issues. 我已经了解到无法对所有这些类使用MarshalByRefObject和[Serializable],否则我将遇到问题。 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. 因此,这就是为什么我认为我需要创建执行“管理”的单独类(例如,Get,AddOrUpdate,Delete),而不是具有Property定义以及Method调用。

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. 然后,要实际创建列表,我将有一个单独的类,称为UserManagement之类。

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

    }
}

Any advice is greatly appreciated! 任何意见是极大的赞赏!

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. 您可能要考虑创建Web服务以用于跨体系结构层的通信。 Windows Communication Foundation (WCF) is a mature technology that makes this pretty straight-forward for simple communication. Windows Communication Foundation(WCF)是一项成熟的技术,它使简单通信变得非常简单。 You may also want to read about Service Oriented Architecture (SOA), perhaps starting with the four SOA tenets . 您可能还想阅读有关面向服务的体系结构(SOA)的信息,也许从四个SOA原则开始

You should not have any trouble reusing your current classes with WCF. 使用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). 服务将为您提供更好的结构,而且WCF技能比.NET Remoting技能要普遍得多(对于需要在您之后接下来管理此代码的人员而言)。

Good luck! 祝好运! -Bill -法案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM