C# – WCF. Service generic methods

cgenericswcf

How can I use generic methods in wcf service?

I wrote this code:

[OperationContract]
void AddItem<T>(T item);

But I receive the following Error:

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.

Best Answer

You simply can't. It's not possible to do that, as soap does not support this. See this article, which mentions how to get around generics, by creating an intermediate local object that is called and casts the object before calling the WCF operation.