【发布时间】:2017-03-02 10:42:01
【问题描述】:
我有一个用于在数据库上执行 CRUD 操作的通用服务,理想情况下我希望将其公开为 WCF 服务,如下所示:
[ServiceContract]
public interface ICrudService<T> where T : class
{
[OperationContract]
T Add(T arg);
// Read ...
// Update ...
// Delete ...
}
很遗憾,WCF 不支持泛型。
所以我想创建一个 WCF 服务,将其他服务作为属性公开。像这样:
[ServiceContract]
public interface IService1
{
[OperationContract]
FooService FooService { get; }
[OperationContract]
BarService BarService { get; }
}
public interface ICrudService<T> where T : class
{
T Add(T arg);
// Read ...
// Update ...
// Delete ...
}
public class FooService : ICrudService<Foo>
{
}
public class BarService : ICrudService<Bar>
{
}
它不会让我将服务用作运营合同。还有其他方法可以实现吗?
【问题讨论】:
-
这是我严重质疑使用服务价值的地方。为什么不能在进程中进行数据库调用?
-
我想允许从客户端调用操作。我需要使用 UWP 应用作为客户端。