I have a wcf web service which is configured for JSON. But my data contracts have inheritance chain. I have a datacontract called RequestMessage and two other datacontracts like Derived1 and Derived2 which are derived from RequestMessage. My service contract has a service operation which is like this BaseResponse GetResult(BaseRequest request). I am decorating the servie contract with KnownTypes. This works fine when used with basicHttpBinding(any SOAP based binding). Will this also works when JSON message is passed ?
Will the service able to identify the proper type of object when I send any of the Derived1 or Deerived2 JSON objects?
You are obviously using polymorphic types. Microsoft’s JSON, which is used for WCF, uses a non-standard extension where they add type information in a field called
__type. If you add this field, it likely will work.Details about what value you have to put at the
__typekey can be found on this MSDN page in the section “Advanced information”.