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

发布于 2025-01-05 09:10:02 字数 1335 浏览 5 评论 0原文

好的,我知道我对 .NET 远程处理非常陌生,并且就最佳实践而言我有一个问题。首先,我已经构建了一个内部应用程序,并且有我引用的 dll 来为我处理所有数据。我希望我的应用程序的服务器版本能够利用所有这些类及其方法,并且能够来回传递这些自定义对象。

我的问题是,我是否应该将 [Serializable] 应用于我想要来回传递的所有类,然后创建专门使用我的方法来获取、AddOrUpdate、Delete 等的特殊类?

现在,我的所有类中都有 Get、AddOrUpdate 和 Delete 方法,它们与数据库来回通信。我已经知道我不能 MarshalByRefObject & [可序列化]到所有这些类,否则我会遇到问题。因此,这就是为什么我认为我需要创建单独的类来执行“管理”(例如 Get、AddOrUpdate、Delete),而不是拥有属性定义和方法调用。

我认为需要做的一个例子。

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

然后,为了实际创建一个列表,我将有一个单独的类,名为 UserManagement 之类的类。

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

    }
}

非常感谢任何建议!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

强辩 2025-01-12 09:10:02

远程处理可能是一个很好的方法,但由于您没有提供很多背景信息来说明为什么要进行远程处理,所以让我提供一个额外的建议。您可能需要考虑创建 Web 服务来跨架构层进行通信。 Windows Communication Foundation (WCF) 是一项成熟的技术,使得此非常简单 用于简单的通信。您可能还想阅读有关面向服务的体系结构 (SOA) 的内容,也许从四个开始SOA 原则

通过 WCF 重用当前的类应该不会有任何问题。服务只会为您提供更好的结构,而且 WCF 技能比 .NET Remoting 技能更常见(对于接下来需要管理此代码的人来说)。

祝你好运! -账单

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文