WCF 公开泛型类型“T" [英] WCF exposing generic type 'T'

查看:43
本文介绍了WCF 公开泛型类型“T"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里为插入和删除操作编写了一个 WCF 服务,我们使用了通用方法,但它给出了以下错误System.Runtime.Serialization.InvalidDataContractException:类型‘T’不能作为架构类型导出,因为它是一个开放的泛型类型.如果泛型类型的所有泛型参数类型都是实际类型,你只能导出它."

I write a WCF service for Insert and delete operation here we used generic method but it gives following error "System.Runtime.Serialization.InvalidDataContractException: Type 'T' cannot be exported as a schema type because it is an open generic type. You can only export a generic type if all its generic parameter types are actual types."

这里的EntityBase2"是所有实体的基类

here "EntityBase2" is base class for all entities

[ServiceContract]
[ServiceKnownType(typeof(EntityBase2))]
public interface IBackupUtility
{
    [OperationContract]
    void Delete<T>(T entity) where T : EntityBase2;

    [OperationContract]
    void InsertORUpdate<T>(T entity) where T : EntityBase2;        
}

问题是如何公开泛型类型T"?

Question is how i can expose generic type 'T'?

推荐答案

这篇文章确实很旧,但也许有人觉得这个解决方案有用:WCF 和泛型

This post is old indeed, but maybe someone find this solution useful: WCF and Generics

这篇关于WCF 公开泛型类型“T"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆