Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF exposing generic type 'T'

Tags:

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'?

like image 669
Vikram Avatar asked Jan 19 '11 06:01

Vikram


1 Answers

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.

like image 193
Pablo Castilla Avatar answered Nov 09 '22 06:11

Pablo Castilla