WCF/webservice architecture question
Posted
by
M.R.
on Programmers
See other posts from Programmers
or by M.R.
Published on 2012-09-21T14:42:08Z
Indexed on
2012/09/21
15:52 UTC
Read the original article
Hit count: 373
I have a requirement to create a webservice to expose certain items from a CMS as a web service, and I need some suggestions - the structure of the items is as such:
item - field 1 - field 2 - field 3 - field 4
So, one would think that the class for this will be:
public class MyItem
{
public string ItemName { get; set; }
public List<MyField> Fields { get; set; }
}
public class MyField
{
public string FieldName { get; set; }
public string FieldValue { get; set; } //they are always string (except - see below)
}
This works for when its always one level deep, but sometimes, one of the fields is actually a point to ANOTHER item (MyItem
) or multiple MyItem
(List<MyItem>
), so I thought I would change the structure of MyField
as follows, to make FieldValue
as object
;
public class MyField
{
public string FieldName { get; set; }
public object FieldValue { get; set; } //changed to object
}
So, now, I can put whatever I want in there. This is great in theory, but how will clients consume this? I suspect that when users make a reference to this web service, they won't know which object is being returned in that field? This seems like a not-so-good design. Is there a better approach to this?
© Programmers or respective owner