【发布时间】:2011-10-13 09:06:11
【问题描述】:
我正在构建 WCF 服务,我有一个关于 WCF 服务设计的问题:
例如:
如果我有一个包含 Person 和 Product 两个类的数据访问层:
public class Person
{
public DataTable Select()
{...}
}
public class Product
{
public DataTable Select()
{...}
}
两个类都有 Select() 方法。为了在 WCF 中使用这些类,我在之前的项目中使用了两种方式
1)创建两个服务类PersonService和ProductService:
public class PersonService : IPersonService
{
public DataTable Select()
{
Person person = new Person();
return person.Select();
}
}
public class ProductService : IProductService
{
public DataTable Select()
{
Product product = new Product();
return product.Select();
}
}
在这种情况下,我必须单独创建/配置服务类。
2) 创建一个服务类并使用不同的名称:
public class MyService : IMyService
{
public DataTable PersonSelect()
{
Person person = new Person();
return person.Select();
}
public DataTable ProductSelect()
{
Product product = new Product();
return product.Select();
}
}
在这种情况下,我只需要创建/配置一个服务类。但是方法有更大的名称(例如:PersonSelect() 而不是 Select())
哪种方法更好?为什么?
谢谢。
【问题讨论】:
标签: c# wcf service-design