WCF一个服务或多个服务

时间:2022-11-30 16:50:37

I am new to setting up WCF, I have it going in my project, but I have like 5 different 'services' in my one WCF project and I am wondering if I am doing the right thing. My services for now are 1-1 to my database tables. I end up having something like:

我是设置WCF的新手,我已将它放在我的项目中,但我在我的一个WCF项目中有5个不同的“服务”,我想知道我是否正在做正确的事情。我现在的服务是1-1到我的数据库表。我最终得到了类似的东西:

public class Projects : IProjects
{
    public List<Project> GetAll()
    {
        return (from p in Connection.Data.Projects
                select new Project {ID = p.id, Name = p.name}).ToList();
    }

    public Project GetByID(int id)
    {
        return (from p in Connection.Data.Projects
                where p.id == id
                select new Project {ID = p.id, Name = p.name}).First();
    }

    public Project AddProject(string name)
    {
        var project = new Data.Projects {name = name};
        Connection.Data.AddToProjects(project);
        Connection.Data.SaveChanges();

        return new Project {ID = project.id, Name = project.name};
    }

    public void DeleteProject(int id)
    {
        var project = (from p in Connection.Data.Projects
                       where p.id == id
                       select new Project {ID = p.id, Name = p.name}).First();

        Connection.Data.DeleteObject(project);
        Connection.Data.SaveChanges();
    }
}

I have a similar class for each of the tables in my project. Should I be finding a way to use 1 service connection with sub classes or keep it as 1 service class per table?

我的项目中的每个表都有一个类似的类。我是否应该找到一种方法来使用与子类的1个服务连接或将其保持为每个表1个服务类?

1 个解决方案

#1


"It depends!" :-) The standard answer for all IT and programming questions :-)

“这取决于!” :-)所有IT和编程问题的标准答案:-)

I don't see anything wrong with having those 5 separate services - you don't really gain anything by merging them all together into one big service, I'd say. I would prefer to keep them separate and "lean'n'mean".

我认为拥有这5项独立服务并没有任何问题 - 我不会通过将它们合并为一项大型服务来获得任何收益,我会说。我宁愿把它们分开并且“精益求精”。

If you have five separate services, you can also manage things like access permissions to them for each one separately, e.g. let certain user groups use one service, while not another.

如果您有五个单独的服务,您还可以分别管理每个服务的访问权限,例如:让某些用​​户组使用一个服务,而不是另一个。

Again: I think you're doing it just fine - I don't see any compelling reason or benefit from having one huge services vs. five smaller, nimbler ones.

再说一遍:我认为你做得很好 - 我没有看到任何令人信服的理由或从一个巨大的服务与五个更小,更灵活的服务中获益。

Come to think of it - the only real change I might suggest is trying to design your services so that they are more closely matched to what your app wants to do (i.e. the operations you expect your app and thus your services to handle), rather than modelling them too closely to the database. Try to think "task-oriented" or in terms of operations, rather than the underlying store where they'll store their data.

想一想 - 我可能建议的唯一真正的改变是尝试设计你的服务,使它们与你的应用程序想要做的事情(即你期望你的应用程序以及你的服务处理的操作)更紧密地匹配,而不是而不是将它们建模得太紧密。尝试思考“面向任务”或操作方面,而不是他们将存储数据的底层商店。

Marc

#1


"It depends!" :-) The standard answer for all IT and programming questions :-)

“这取决于!” :-)所有IT和编程问题的标准答案:-)

I don't see anything wrong with having those 5 separate services - you don't really gain anything by merging them all together into one big service, I'd say. I would prefer to keep them separate and "lean'n'mean".

我认为拥有这5项独立服务并没有任何问题 - 我不会通过将它们合并为一项大型服务来获得任何收益,我会说。我宁愿把它们分开并且“精益求精”。

If you have five separate services, you can also manage things like access permissions to them for each one separately, e.g. let certain user groups use one service, while not another.

如果您有五个单独的服务,您还可以分别管理每个服务的访问权限,例如:让某些用​​户组使用一个服务,而不是另一个。

Again: I think you're doing it just fine - I don't see any compelling reason or benefit from having one huge services vs. five smaller, nimbler ones.

再说一遍:我认为你做得很好 - 我没有看到任何令人信服的理由或从一个巨大的服务与五个更小,更灵活的服务中获益。

Come to think of it - the only real change I might suggest is trying to design your services so that they are more closely matched to what your app wants to do (i.e. the operations you expect your app and thus your services to handle), rather than modelling them too closely to the database. Try to think "task-oriented" or in terms of operations, rather than the underlying store where they'll store their data.

想一想 - 我可能建议的唯一真正的改变是尝试设计你的服务,使它们与你的应用程序想要做的事情(即你期望你的应用程序以及你的服务处理的操作)更紧密地匹配,而不是而不是将它们建模得太紧密。尝试思考“面向任务”或操作方面,而不是他们将存储数据的底层商店。

Marc