Passing object type to WCF Service Application in VS 2010 RRS feed

  • Question

  • I need to pass different types of objects to the same class i.e. CompositeType, CompositeType2, CompositeType3, etc.

    So, based on the VS2010 WCF Service Application template here's the method that accepts a typeof(object) as a parameter:

    CompositeType GetDataUsingDataContractAsObject(object composite)

    instead of the default WCF Service Application method:

    CompositeType GetDataUsingDataContract(CompositeType composite)

    The following method works:

    string GetDataAsObject(object value);

    instead of the default WCF Service Application method:

    string GetData(int value);

    But not:

    CompositeType GetDataUsingDataContractAsObject(object composite);

    Here's the implementation:





        tmpCompositeType = (



    if(tmpCompositeType == null)







    tmpCompositeType.StringValue +=






    The error I get is:

    The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter

    The InnerException message was 'Error in line 1 position 302. Element 'composite' contains data from a type that maps to the name 'CompositeType'. The deserializer has no knowledge of any type that maps to this name. Consider using a DataContractResolver or add the type corresponding to 'CompositeType' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.'.  Please see InnerException for more details.

    Adding the KnownTypeAttribute didn't work.

    I want the minimum complexity required to make it work i.e. I don't want to replace the deserializer that is being used...I just want to fix the error, "The deserializer has no knowledge of any type that maps to this name" so that it knows what a CompositeType is.  Is there something that I need to add to the CompositeType class?  Is there anyway to let the deserializer know about the CompositeType type?

    Friday, February 27, 2015 6:39 PM


All replies