tags:

views:

22

answers:

2

is this really necessary, or is there any framework that do this job for me? Thank you

A: 

Something to consider is WCF Data Services, where you enable your entities to be accessible over the wire. I'm not sure if that is in line with your requirements or desire, but it is possible. If you're using Entity Framework 4 (.NET 4), then exposing part of your entity model via WCF Data Services is very easy to do.

Some benefits:

  • you get CRUD functionality;
  • data exposed to your client via XML or JSON;
  • you can lock down CRUD actions to the entity level (e.g. expose Orders to full CRUD operations, but only allow Products to be read and updated);
  • utilize REST (e.g. HTTP verbs GET, PUT, POST, DELETE);
  • consistent OData data format (AtomPub);
  • easy to query your data using the querystring (not sure if some people think this is a pro or a con!);
  • probably a few more that I'm forgetting

Some negatives:

  • You don't have access to the full WS-* functionality, since this is WCF REST;
  • Security is a bit of a roll-your-own at this point -- you can either piggy back on an existing site's security model (like forms auth) or you are manually inserting and reading tokens from request headers. (There's other blogs out there about securing WCF Data Services, so I'm probably missing a few items here);
  • If you're not using EF4, then exposing your entities for insert/update/delete is more work, as you have to implement the IUpdateable interface. You also have to expose your entities for reading by exposing an IQueryable method.

So I'm not sure if this is what you're looking for, but maybe it's something to consider. The documentation on MSDN is pretty good, and it seems to get better each month (it was pretty sparse 4-5 months ago!). Also, check out the OData spec online, too.

MSDN for WCF Data Services -- http://msdn.microsoft.com/library/cc668792.aspx OData spec -- http://www.odata.org/ Blogs by Pablo Cibaro, Pablo Castro, and the data services team (they have a series on authentication/authorization).

I hope this helps!

David Hoerster
A: 

You don't need to. You only need to use serializable types known by service but it don't have to be special DTO used just for communication. Usage of DTOs is simply matter of application architecture. When complexity of application and exposed logic rises you will find DTOs as useful design feature but for simple applications it is just overhead.

Ladislav Mrnka