Webservice Return Generic Result Type or Purposed Result Type

Posted by hanzolo on Programmers See other posts from Programmers or by hanzolo
Published on 2012-09-19T06:07:31Z Indexed on 2012/09/19 9:51 UTC
Read the original article Hit count: 246

Filed under:
|
|
|

I'm building a webservice which returns JSON / XML / SOAP at the moment.. and I'm not entirely sure which approach for returning results is best.

Which would be a better return value?

A generic "transfer" type structure, which carries Generic properties or a purposed type with distinct properties:

class GenericTransferObject{
    public string returnVal;
    public string returnType;
}

VS

class PurposedTransferObject_1{
  public string Property1;
}

//and then building additional "types" for additional values
class PurposedTransferObject_2 {
  public string PropertyA;
  public string PropertyB;
}

Now, this would be the serialized and returned from a web service call via some client technology, JQuery in this example. SO if I called:

/GetDaysInWeek/

I would either get back:

{"returnType": "DaysInWeek", "returnVal": "365" }

OR

{"DaysInWeek": "365"}

And then it would go from there.

On the one hand there's flexibilty with the 1st example. I can add "returnTypes" without needing to adjust the client other than referencing an additional "index"..

but if I had to add a property, now i'm changing a structure definition..

Is there an obvious choice in this situation?

© Programmers or respective owner

Related posts about c#

Related posts about JavaScript