Am I using DTOs wrong with my service?

I currently have a WCF service that exposes a SOAP enpoint. In this webservice I have the following metthod:

    public List<DataField> GetAvailableFields(string accountNumber, string accountKey, Models.Enums.CountryEnum country)
        //Code that builds DataFields
        return dataFields;

My Datafields may look something like this

public class DataField
    public DataField()
        AlternativeFields = new List<DataField>();
    public string FieldName { get; set; }
    public string Value { get; set; }
    public bool IsRequired { get; set; }
    public List<DataField> AlternativeFields { get; set; }
    public DataField ParentField { get; set; }

So I have 2 questions.

1: The ParentField reference...I am guessing that this needs to go as I'm not sure how that would serialize

2: Is it appropriate to have my list of alternative fields? This is essentially a list of DTOs inside a DTO but it seems that this should serialize just fine and there should be no interoperability issues with this. In it bad practice to have DTOs inside other DTOs?

Thank you and feel free to point out anything I am doing incorrectly.


1) The parent field doesn't have the DataMember decorator on it, so it won't serialize in the first place.

Supposing that it did have the decorator on it, you'd still be ok and it would serialize properly (since DataField is a data contract). However, you need to be careful that you don't get into loops with this and start sending over everything for infinity times (that's a good way to get an exception).

2) The List of DTOs are fine. Once again, however, you need to make sure that you're not sending over duplicate data. Just send the data you need, and process it on the other end.

Generally, I send a list of DTOs, all with unique IDs, and they would all have Lists of Int32's pointing to those unique IDs. However, if there are being sent over only for this purpose, then this is fine.

If the entire dataset will be required, then it's perfectly legitimate to have DTOs within DTOs. Otherwise consider sending only enough information for your domain entities to be fully populated (eg IDs of referenced entities).

FYI The parent field should serialize fine (as long as there are no cyclic references).

Need Your Help

Having issues removing UIViews from a UIScrollView

objective-c cocoa-touch oop

I'm trying to make code that will add players to a view based on objects but, I'm having some issues.

Why are error_logger messages in different order on the console compared to error_logger_mf file

erlang error-logging

I'm looking at error_logger messages on the console and store them in a file with error_logger_mf at the same time.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.