I have a service contract that defines a method with a parameter of type System.Object (xs:anyType in the WSDL). I want to be able to pass simple types as well as complex types in this parameter. Simple types work fine, but when I try to pass a complex type that is defined in my WSDL, I get this error:
Element ‘http://tempuri.org/:value‘ contains data of the ‘http://schemas.datacontract.org/2004/07/MyNamespace:MyClass‘ data contract. The deserializer has no knowledge of any type that maps to this contract. Add the type corresponding to ‘MyClass’ 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.
Adding it as a known type doesn’t help because it’s already in my WSDL. How can I pass an object of a complex type via an ‘xs:anyType’ parameter?
More info:
I believe this works when using NetDataContract, but I can’t use that because my client is Silverlight.
I have seen references to complex types explicitly extending xs:anyType, but I have no idea how to make WCF generate a WSDL that does that, and I have no idea whether or not it would even help.
Thanks
I have solved this problem by using the ServiceKnownType attribute. I simply add my complex type as a service known type on my service contract, and the error goes away. I’m not sure why this didn’t work last time I tried it.
It doesn’t appear to affect the WSDL in any way, so I suspect that the serialized stream must have some difference that informs the deserializer that the object can be deserialized using my type.