views:

429

answers:

4

What is the proper way to handle polymorphic business objects in a WCF/SOAP world?

It seems to me that SOA and OOP are at odds with each other - to expose a clean WSDL you need concrete objects, typically not even utilizing inheritance. On the other hand, presumably in the underlying system, you'll want to follow proper OO design.

What do people typically do here? Build a set of WCF contract objects, forgoing OOP principles, then convert to and from another set of objects in the actual logic layers?

+1  A: 

After reading the Thomas Erl library, I came to the following conclusion:

Think of the WCF Contracts/SOAP Message as simply a message that the Services use to communicate (don't tightly tie that to Objects in your code).

You can then use OOP to design a code-base that gracefully handles those messages using common OOP techniques.

Justin Niessner
A: 

You use an abstraction (interface type) annotated with WCF attributes in order to define your Service contract.

This is both depending on abstraction, which is according to OOP, as well as defining a service endpoint, which is SOA.

In general, if you find that you are getting business objects with dependencies, you should consider pulling such dependencies up to the service business layer as opposed to inject dependencies into the business objects. The service business layer will then act as a mediator acting on both the WCF service proxy as well as the business objects. As opposed to having the business objects acting on the WCF service proxy.

Tormod
+3  A: 

What do people typically do here? Build a set of WCF contract objects, forgoing OOP principles, then convert to and from another set of objects in the actual logic layers?

Yes.

The way WCF serializes things ends up putting a lot of limitations on what you can and can't do with the contract objects. What you can't do ends up being "most anything useful".

I've found it makes things much clearer if you think of the WCF-contract objects as just a data transfer mechanism. Basically like strongly/statically typed XML.
Instead of converting your business object to an XML string (and back again), you convert your business object to a WCF-contract object (and back again), but it's otherwise similar

Orion Edwards
So would you add a `.ToWCFDataContract()` method and a constructor that accept your WCFDataContract object to your business objects?
Nate Bross
Thanks very much.It's a little disheartening to think I have to create another set of objects (it's not a small service, to say the least), but now that I know there isn't a better option out there, I won't be feeling like I'm wasting my time.
mdryden
@Nate: Pretty much, yeah
Orion Edwards
A: 

All great comments on this topic! I'll add my vote to the notion of an adapter for mediation between your service orientation and object orientation. I also like Thomas Erl's approach where in his service model he introduces the notion of "application services" and "business services." These are the way to go for your integration points with your specific application/business environment (i.e. your object oriented and component oriented framework/API). This way should result in much better composability and thus capability, for you enterprise framework gurus out there.

Timex