[ServiceContract] public interface ITest<T> { [OperationContract] T GetEntity(); }
public class Test<T>:ITest<T>{
public T GetEntity(){
return null;
}
这样定义服务契约,配置文件中怎样写<service>服务节点??
1.泛型机制属于C#的语言特性。
2.WCF不支持泛型方法。
这个原因不是因为WCF不能实现,是因为WCF背后的Web服务规范,有个服务元数据需要WSDL来描述,这个标准无法提供泛型的描述信息,因此WCF只能使用具体的类型。
这个有个英文的帖子讨论。http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/79585667-6b97-4ce4-93fa-3a4dcc7a9b86
微软WCF中文技术论坛 微软WCF英文技术论坛 Windows Azure中文技术论坛