Freigeben über


Revealing the Hierarchy

I have a hierarchy of types that I'm using in service data contracts. When I change the service implementation, sometimes this shifts things so that a different set of the base classes and derived classes are exposed by the service. How do I present a consistent set of types without losing the ability to change the service implementation?

The issue here is that two data contracts that are essentially the same can differ in detail depending on whether the projected type is the base class of a hierarchy or the most derived class of a hierarchy. One approach is to use a disciplined consistency in the construction of the service contract so that the set of exposed types does not change over time. Often, this requires some coordination as everyone working on each of the contracts has to work in a coordinated fashion. A mistake in the design will cause the set of types to change, but this can then be tested for by automated processes that compare the set of projected types against a baseline.

The alternative approach is essentially the opposite, which is to project all of the types in the hierarchy regardless of whether they're used in the current implementation. This approach again keeps the set of types consistent as the service implementation changes even though the set of types is different than the one in the first approach. You can project the additional types using standard mechanisms, such as KnownType declarations.

The two approaches have different consequences for service versioning. In the first approach, maintenance of the set of types is very simple but there is a coupling present in the service contract that is very much in the spirit of compatibility requirements for binary linking. In the second approach, maintenance of the set of types tends to be more unruly but the degree of polymorphism offered by having a full type hierarchy is something that can be leveraged in future versions. By adding new types that superset the hierarchy, additional information can be passed for service calls that are aware of the new version. The older type bindings are still usable although obviously they don't have any access to the new features.

Next time: Choosing a Port