Search code examples
asp.net-mvcwcfdto

Can I expose my DTO classes to a WCF Client, or should I use the auto generated ones instead?


I am currently working on an N-Tier application using MVC4 on the front for the UI, which then talks to WCF services, and which then call out to the Business Layer which uses EF to get the data out of Oracle.

I have created a set of DTO objects which are populated from EF, and get sent to the UI via the WCF services. My question is this...

When I add the Service Reference in the UI, I get the DTO classes recreated a part of the service code in Reference.cs. Is this ok, or should I be adding a reference to the original DTO classes project instead?

Is it purely a dev choice, or are there specific benefits or pitfalls or either approach?

Any help would be much appreciated.

Thanks, Nick


Solution

  • A benefit of using your original contract assembly is that when that contract changes, you get compilation errors in your client assembly. If you used a generated client, that would compile and then crash at runtime. Especially with Continuous Integration, you want to get errors as early as possible, compile time is great.

    Depending on your generated client implementation, it may have INotifyPropertyChanged already implemented. That's probably more than your DTOs can do. DTOs should not implement that. So if you are going to reimplement all your DTOs again on the client side anyway to use this interface, you might argue that using the generated classes already gives you this benefit.

    So in the end... it's purely a dev choice.