[DataContract], the Holy Roman Empire of Distributed Computing

The Holy Roman Empire was, as Voltaire famously remarked, "neither Holy, nor Roman, nor an Empire." Likewise, the [DataContract] in Indigo is neither data nor a contract. Moreover, like the putative Empire, the [DataContract] will never reach its rather ambitious goals, due to the inherent contradictions of its conflicted nature. Just as the German kings who styled themselves emperors initially used the imprimatur of the Papal crowning to enhance their power and prestige but eventually were irreversibly weakened by that dependence, the [DataContract] gains a great deal of apparent power from its connection to your domain object model, but its dependence on your internal object model ultimately undermines its utility.

Not a Contract

A contract is "an agreement between two or more parties."  In most discussions of services, the term contract is used in an entirely inappropriate fashion. Because the consuming side of the "contract" is unknown at the time the "contract" is published, we should hardly be calling this thing a contract. When you specify the [DataContract] in an Indigo app, you are stating both an expectation and a commitment. Your expectation is that consumers of your service will send you the specific type of message you are describing and your commitment is that, if the message meets your specification, you will do something with it. Most (but not all) of the versioning problems that contract-based distributed computing stacks have are a direct result of mistaking this expectation and commitment for a contract. If we want to build real-world business systems effectively, we need to be able more flexibility than a contract allows. For example, we need be able to specify multiple (potentially unrelated) message types with the same endpoint and operation. Rather than a system that, like both Indigo and ASMX, completely hides the transformation between the messages and our internal processing model, we need a system that surfaces that transformation to the developer. The transformation between the external messages and internal processing is a key part of the business logic of any service. Having to control that transformation indirectly through attributes is slow, frustrating, and error-prone.

Not Data

The problem with thinking of messages as data is that data has no meaning on its own. One of the differences between RPC and message-oriented programming is that messages, unlike the parameters of an RPC, can have meaning outside the particular service endpoint to they are addressed to. The [DataContract]/[DataMember] paradigm works fine if your understanding of what you're doing is mapping individual parameters of a remote call to the state of an object, but it breaks down quickly if you want to actually design a message with rich semantics. It is certainly possible to achieve a message with rich semantics using the paradigm, but the attribute-based approach is clumsy at best. The important semantics of the message are controlled by the relationship of the attributes to the class members.

Not the Best Way to Design Messages

Designing the messages that your services process is a key part of building a service oriented architecture. In the Indigo model, the preferred way to do this is to design a class (that is part of your internal processing model) and annotate that class with the appropriate attributes. This seems to be part of a deliberate strategy to hide the message from the developer. As an Indigo developer using the [DataContract] mechanism, your primary view of the message is a fragmented set of attributes attached to a class. Your secondary view is a confusing XML Schema that's cluttered with detritus needed only to support the Indigo infrastructure. In neither case is it easy to tease out what a instance of your message would actually look like. There's a very clear assumption that the XML Schema that is generated is only going to be consumed by toolsets similar to Indigo. These schemas should have annotation stating "Not Intended for Human Consumption." Unfortunately, the sheer complexity of supporting all of the [DataContract] magic makes it very difficult for alternate toolsets to productively consume these schemas (or schemata, if you prefer). This will limit interoperability for developers going down that route.

If Not [DataContract], Then What?

Of course, you always have the option of designing an XML Schema in some alternative tool and generating a .Net class from it. Unfortunately, Indigo doesn't seem to have advanced the state of the art very much here. That's more due to the inherent complexity of XML Schema than any Indigo deficiency. Starting from an XML Schema design leads one down a path of creating message types that are difficult, if not impossible, to consume in .Net (dealing with dates is but one obvious example). Beyond that, XML Schema is, in many respects, ill-suited for message design. First, and foremost, schema validation is all or nothing. While for some scenarios that is a good thing, for many scenarios all or nothing validation is inappropriate. For example, there is no easy way to design a schema that will ignore an optional element with the wrong datatype (as far as I know, I'm never quite sure about anything with XML Schema).

Is [DataContract] Evil?

Not at all. In fact, if you have an existing object model that you want to expose to an Indigo service, it is a great tool. I just don't think it is the best way to design new services because it directly couples your service's messages to your internal processing model via an enormous hidden infrastructure that you can affect only by cumbersome, trial and error attribute twiddling. In spite of that, I expect it will be fairly successful. Just as the Holy Roman Empire lasted for the better part of a millennium in spite of its rather obvious flaws, [DataContract] will be the basis for a generation of distributed applications.  

Posted Jun 04 2005, 12:13 PM by john-cavnar-johnson

Comments

Dave Angers wrote re: [DataContract], the Holy Roman Empire of Distributed Computing
on 06-04-2005 2:52 PM
Fortunately, I don't believe that [DataContract] is the only way to use Indigo, I believe that Indigo can also do a great job of transporting messages/documents. It has been a long path from processing 80-col cards to dealing with loosely formated data. I wonder how useful it would be to consume the XML output from Word 12 via [DataContract]! There will often be many advantages to working directly with the XML so learning how to do so will be a usefull skill. Hopefully, someday, the languages will catch up to make the work easier.
Anon wrote re: [DataContract], the Holy Roman Empire of Distributed Computing
on 06-05-2005 10:38 AM
So, do we use Indigo with the XmlSerializer and design contracts in other tools?
Mike Taulty's Weblog wrote Indigo and DataContract
on 06-05-2005 11:40 AM
Mohair Sam wrote Programming by contract a bad idea?
on 06-05-2005 12:53 PM
Sam Marcuccio wrote re: [DataContract], the Holy Roman Empire of Distributed Computing
on 06-06-2005 2:18 PM
Perhaps we need something closer to this? http://weblog.infoworld.com/udell/2005/05/25.html
Dion Hinchcliffe's Blog - Musings and Ruminations wrote Comparing SDLs: An Approach to Consuming Services and Their Descriptions
on 06-07-2005 3:49 AM
YeYan wrote re: [DataContract], the Holy Roman Empire of Distributed Computing
on 06-08-2005 6:53 AM
RePost:
http://www.yeyan.cn/SoftwareEngineering/DistributedComputing.aspx
Sergey Korkin blog wrote Интересное
on 06-08-2005 10:35 AM
??????? ??????? ?????? ?????, ????? ????????? ?????????? ?????:

JCooney.NET wrote If not schema, then what?
on 07-14-2005 10:24 AM
Cordell Lawrence wrote re: [DataContract], the Holy Roman Empire of Distributed Computing
on 06-21-2006 5:07 AM
Just a few thoughts

<quote>
A contract is "an agreement between two or more parties." In most discussions of services, the term contract is used in an entirely inappropriate fashion. Because the consuming side of the "contract" is unknown at the time the "contract" is published, we should hardly be calling this thing a contract.
</quote>


I agree that the word ‘contract’ can lead to some semantic conflict there, ‘Terms of Use’ seem to be a better suited phrase i.e. The service publicly states, “I’m am a service, these are my operations, this is the data and the format that I will accept. I can only understand your intent if you send me a message with the following operation with the respective data in the format described …” etc. However disagree that it is entirely inappropriate. Not all contracts are drafted with explicit knowledge of universe of entities/persons that will agree to/sign said contract. Some “None Disclosure Agreement” contracts leave no room for discussion, either you accept the terms of us working together specified by the contract or you don’t, while others can be negotiated/customized. I think the use of the word contract here is describes these ‘generic’ contracts type, those that employees sign when joining an organization that aren’t re-written for every individual joining the company.

<quote>
Rather than a system that, like both Indigo and ASMX, completely hides the transformation between the messages and our internal processing model, we need a system that surfaces that transformation to the developer. The transformation between the external messages and internal processing is a key part of the business logic of any service. Having to control that transformation indirectly through attributes is slow, frustrating, and error-prone.
</quote>

Interesting, I would like to find out more about why you think this. I rather like the whole ‘Services are atomic’ notion and don’t really care about the other guys internal representation of the message.

For the most part I agree with the rest of the post :) In systems oriented around message exchange developers should have access to the message as a first class citizens and not some entity of another type system that I hope gets rendered as my message after some processing. That said though, I think they've done a pretty good job which covers most of the simpler service contract requirements. I hope better tools are coming soon though and smarter code generators so that I can design and view my messages as XML (if this continues to be the service lingua franca) and be confident when manipulating my internal object representation that it will be rendered to my message correctlyon the wire.

Add a Comment

(required)  
(optional)
(required)  
Remember Me?