WCF exposing generic type ‘T’

wcf

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."

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;        
}

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

Best Answer

I think it is imposible, how could it generate the wsdl that way?

You have two options:

  • You could send the type as a parameter.

  • If you want to expose crud operations for entities I would recommend to use a code generator, maybe a T4 template for EF.

Related Topic