I want a loosely typed parameter in my web method.
I have a scenario where the client can send any of 25 DataContract objects into the WCF operation e.g.
proxy1.myFunction(PersonObject)
proxy1.myFunction(ComputerObject)
My restriction is there should be only one Operation Contract exposed to the client.
How can I design a web method which can take any of the 25 DataContract classes as a parameter? I tried with object as type of parameter and gave KnownType attribute to the DataContract classes but I had no luck during the serialization process.
I have just done this, I found you need to add the KnownTypesAttribute to the interface.
in you implementation, you will need to check the type to ensure it is one of your DataContracts.
EDIT
If you have a lot of contracts, you can use reflection to add them to the KnownTypes.
Then you can declare your interface as,
This is a much cleaner way of doing it.