Sunday, January 23, 2005
« From VAX to Windows | Main | More on web services and DataSet objects... »

Every now and then the question comes up about whether to pass DataSet or DataTable objects through a web service.

 

I agree with Ted Neward that the short answer is NO!!

 

However, nothing is ever black and white…

 

For the remainder of this discussion remember that a DataSet is just a collection of DataTable objects. There’s no real difference between a DataTable and DataSet in the context of this discussion, so I’m just going to use the term DataSet to mean 1..n DataTables.

 

There are two “types” of DataSet – default and strongly typed.

 

Default DataSet objects can be converted to relatively generic XML. They don’t do this by default of course. So you must choose to either pass a DataSet in a form that is pretty much only useful to .NET code, or to force it into more generic XML that is useful by anyone.

 

To make this decision you need to ask yourself why you are using web services to start with. They are designed, after all, for the purpose of interop/integration. If you are using them for that intended purpose then you want the generic XML solution.

 

On the other hand, if you are misusing web services for something other than interop/integration then you are already on thin ice and can do any darn thing you want. Seriously, you are on your own anyway, so go for broke.

 

Strongly typed DataSet objects are a different animal. To use them, both ends of the connection need the .NET assembly that contains the strongly typed code for the object. Obviously interop/integration isn’t your goal here, so you are implicitly misusing web services for something else already, so again you are on your own and might as well go for broke.

 

Personally my recommendation is to avoid passing DataSet objects of any sort via web services. Create explicit schema for your web service messages, then generate proxy classes in VB or C# or whatever language based on that schema. Then use the proxy objects in your web service code.

 

Your web service (asmx) code should be considered the same as any other UI code. It should translate between the “user” presentation (XML based on your schema/proxy classes) and your internal implementation (DataSet, business objects or whatever).

 

I discuss this in Chapter 10 of my Business Objects books, but the concepts apply directly to data-centric programming just as they do to OO programming.


Sunday, January 23, 2005 11:29:44 PM (Central Standard Time, UTC-06:00)
Gotta disagree with Rocky on this one !!

http://dotnetjunkies.com/WebLog/sahilmalik/archive/2005/01/23/47832.aspx
Monday, January 24, 2005 12:31:00 AM (Central Standard Time, UTC-06:00)
I've responded to this blog on my blog...

http://adoguy.com/content.aspx?id=rantview&rantid=159
Monday, January 24, 2005 3:01:49 AM (Central Standard Time, UTC-06:00)
Rocky,

I agree with your logic, that exposing a .NET data format via web services bad, since it makes interop difficult.

However, I would like to question one minor point. You write that typed datasets cannot be exposed as generic XML documents. Are you sure? I would have thought that a typed dataset can be exposed in exactly the same way as an untyped one. Afterall, all typed datasets are subclasses of DataSet...
Monday, January 24, 2005 3:50:25 AM (Central Standard Time, UTC-06:00)
I am that bad man. Im out there on my own. Thing is I know Im doing wrong, to bypass other problems out of my control. Sometimes we do things because we work in the real world with crazy deadlines and other politics.

Doesnt make it any less wrong.

I have a bunch of java guys who use my strongly typed dataset webservice and just treat it as XML, they want to kill me, but they use it rather than write another.

Perhaps what Im trying to say is just I agree, but reserve the right to mess it all up anyway.
SimonT
Monday, January 24, 2005 8:49:55 AM (Central Standard Time, UTC-06:00)
My primary message is that web services can be used for interop/integration (their intended purpose), or other things such as n-tier development.

If you are using them for their intended purpose then passing DataSet objects is bad, because DataSet objects are hard to consume in other platforms – thus defeating the interop/integration purpose.

If you are (mis)using web services for n-tier or some other purpose then who cares what you do. You are communicating between your code and your code, so do what you will.

Several comments on the previous entry are right: We all reserve the right to misuse web services for purposes other than what they are intended for. We all reserve the right to use web services for n-tier development, even though they aren't designed for the purpose and are far from the optimal technology for the purpose.

We always do this with technology. In many cases the sub-optimal web service technology is "good enough" for n-tier purposes, and we choose to live with the bloat. Outside of the open-source world few people complain about bloat anymore, and I think that’s because we’re all guilty as hell and don’t want to be hypocrites.

Personally I’ve used web services for n-tier. Not because it is good (because it isn’t), but because the client required it. No problem, you can easily pass a byte stream through a web service and get real n-tier functionality with full .NET type fidelity.

If you are doing n-tier development with web services then your tiers trust each other, and you can pass DataSets, business objects or whatever you like.

But if you are doing actual service-oriented design then you MUST provide encapsulation, and thus can NOT expose your internal data structures to the outside world.

This is why I don’t hold out much hope for service-oriented design. Very few people are actually going to have the discipline to do any of this stuff right, so they’ll end up with the same point-to-point, tightly coupled solutions we had with RPC, DCOM, RMI and every other protocol in the history of computing.

Same old mistakes, but now new and improved because we can make them with angle brackets! :-)
Comments are closed.