WCF/webservice architecture question
- by M.R.
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?