2

My current set up is an ASMX web service that has an Item object, and returns a List<> of Items.

Item has 114 fields of various types. It is consumed by .NET web apps, as well as Java web apps (using Axis2 to generate a client proxy).

My problem is that every time we want to add a field to the result set, we have to modify the service to add the field to the object, as well as generate a new client proxy for the java side. Also, the mapping of the sql fields to the object fields is one large method loading each field from the datareader into the object, making sure to convert to the proper datatype.

Is there a more dynamic way to do this? I looked into a list of Dictionary, but that cannot be serialized. An alternative is to send a List<> of Struct with Key and Value fields. This now puts the effort of parsing the types onto the client, which isn't necessarily optimal.

Is there a pattern that handles something like this, or barring that, does anyone have a good solution to help make this a little more maintainable? I'm open to converting it to WCF (though I am not too familiar with WCF) if there is a decent way for our Java apps to consume the service.

If you need more details, just ask. Thanks!

IronicMuffin
  • 4,182
  • 12
  • 47
  • 90

1 Answers1

4

Outside of using something like a List<KeyValuePair<string, object>> I don't think you're going to find any other solution; WCF isn't going to help much in that respect.

I think that's actually a good solution, it will make the reading of your data much simpler and scalable, and you wouldn't need to change your server side code much when you add new fields.

You could write code on the clients that do the work of mapping the value pairs back to a real structure, and then most of the code changes (when a field is added) is isolated to your clients. Also, if your clients don't need the new fields, you can just ignore the changes without breaking anything.

CodingGorilla
  • 19,612
  • 4
  • 45
  • 65
  • I had thought of `KeyValuePair`, but a list of pairs only gives me the fields for one record... So I'd have to return a `List>>` ...which I'm not even sure works. – IronicMuffin Sep 22 '11 at 16:58
  • I was using the `KeyValuePair` mostly to express the idea, but you are correct. Personally I would do `List[]>` (.net 4 only), but there are a bunch of variations you could use. – CodingGorilla Sep 22 '11 at 17:24
  • Worked great. I used `List> mylist = new List>()` and http://stackoverflow.com/a/13277616 to get a serialised json. – kkuilla May 09 '14 at 11:45