【发布时间】:2012-11-20 13:29:05
【问题描述】:
我试图通过使用泛型和城堡 WCF 设施来最大程度地减少大型项目的 WCF CRUD 部分的代码编写。
我有 WCF 服务合同:
[ServiceContract]
public interface IResourceService : ICRUDService<DTOResource>
{
[OperationContract]
DTOResource Get(long id);
}
和generic接口
public interface ICRUDService<T> where T is IDTO
{
T Get(long id);
}
也是通用的MVC 控制器(1 个控制器,用于 dto 和服务的所有基本 crud)
public class CRUDController<T> : Controller where T is IDTO
{
readonly ICRUDService<T> service;
public CRUDController(ICRUDService<T> service)
{
this.service = service;
}
}
在客户端,我在Windsor Container 中注册 WCF 客户端
Component
.For<IResourceService , ICRUDService<DTOResource>>()
.AsWcfClient(... standard stuff... )
一切正常,组件和服务已注册,控制器已正确创建, 服务
readonly ICRUDService<T> service;
in 控制器的类型是
Castle.Proxies.IResourceService
但是当我尝试在控制器中使用服务时出现错误
Method Get is not supported on this proxy, this can happen if the method is
not marked with OperationContractAttribute or if the interface type is not
marked with ServiceContractAttribute.
当在控制器中时我硬编码转换
((IResourceService)service).Get(id);
一切正常,所以我相信这个问题是可以解决的。
我也尝试过使用 Forward(结果相同):
Component
.For<IActionTypeService>
.Forward<ICRUDService<DTOResource>>().AsWcfClient(...
如何让它发挥作用?
【问题讨论】:
标签: wcf inversion-of-control castle-windsor wcffacility