locked
WCF Service Returning Object Array RRS feed

  • Question

  • I have a WCF service with a method that returns an object array. The reason I am using an object array is due to the fact that it will return different objects depending on a flag. For instance it might return an array of 'Customers' or an array of 'Employees' or an array of 'Accounts', etc. I am testing with a single object right now, my custom class 'Customers'.

    My customers class is in a different assembly, but it is marked with the DataContract attibute and all properties are marked as DataMember.

    My WCF service is marked with a KnownType(GetType(Customers)) attribute.

    When I call the method from my Silverlight 3 application, I get the error:

    The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter :GetPrimaryKeyResult. The InnerException message was 'Error in line 1 position 238. Element 'http://schemas.microsoft.com/2003/10/Serialization/Arrays:anyType' contains data of the 'http://schemas.datacontract.org/2004/07/BusinessObjects:Customers' data contract. The deserializer has no knowledge of any type that maps to this contract. Add the type corresponding to 'Customers' 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.

    Any help on this would be GREATLY appreciated!!!

    Thanks, Adam
    Friday, January 15, 2010 10:52 AM

Answers

  • My WCF service is marked with a KnownType(GetType(Customers)) attribute.
     

     

    ServiceKnownType may be the attribute you need...

     

    Friday, January 15, 2010 2:57 PM