0

I would like to represent polymorphic data in a dotNET SOAP web service implemented either in WCF or ASMX in such a way that the schema properly reflects my intentions.

In particular I am interested in the closed polymorphism (AKA sum type AKA tagged union AKA algebraic data type...) required to express structured data such as JSON.

This is a question that has been asked in different forms many times. However answers often claim that it is impossible even in principle to represent polymorphism in a messaging protocol. e.g.

WCF MessageContract Inheritance

Of course allowing open polymorphism, that is to say allowing X to be of any type which implements interface I, raises non-trivial design questions. However closed polymorphism (X may be any of the types T1, T2, T3) is not a difficult thing to design a protocol for, indeed http://www.w3.org/2001/XMLSchema has substitutionGroup which does exactly this job. See:

Defining recursive algebraic data types in XML XSD

Everything I have read until now suggests that neither WCF nor ASMX are able to generate schemas with substitutionGroup or any other means of properly expressing polymorphism. Instead I am left with listing the concrete types in a KnownTypes property on the data contract and hope for the best.

If that really is the best we can do, this seems like a failure to express a pretty basic interface concept and I am sure the good folks at Microsoft have a very good excuse. I would be grateful if anyone can enlighten me as to the reason.

Community
  • 1
  • 1
maninalift
  • 703
  • 6
  • 10

0 Answers0