WCF displaying the generic type 'T'

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

here "EntityBase2" is the base class for all objects

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

The question is, how can I set the generic type 'T'?

+5
source share
3 answers

I think this is not possible, how can it generate wsdl this way?

You have two options:

  • .

  • crud , , , T4 EF.

+7

, , , - : WCF Generics

+6
  • : . .
  • , .
  • , .

    [DataContract]
    public class MyGenericObject<T>
    {
       private T _id;
    
       [DataMember]
       public T ID
       {
          get { return _id; }
          set { _id = value; }
       }
    }
    
    [OperationContract]
    MyGenericObject<int> GetGenericObject();
    

, , , , .

WSDL :

[DataContract]
public class MyGenericObjectOfint

We can see that what we get from WSDL is not a general data contract. A WSDL proxy generates a class with a new name using some kind of convention.

Convention used

Generic Class Name + "Of" + Type Parameter Name + Hash

A hash is not always generated; it is generated only when there is a chance of a name clash.

+1
source

All Articles