Ask a questionAsk a question
 

Proposed AnswerCovert Normal Class To DataContract Class

  • Wednesday, November 04, 2009 11:04 AMMatelin Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi ,
    I have an n tier application that have interface, entities, biz layer ..etc .
    I start reading about wcf to expose some methods as service .  

    let say ihave a method something like  => public MyType Method1(MyType2 obj)  and i want to expose it,
    i realized that i have to declare MyType2 as DataContract to enable passing it as parameter over service.

    My question is : can i modified my MyType2  to be a DataContract so i can use it on my wcf service ,
    is this will effect my normal component which usses  MyType2  as normal class ,
    or will it effect any thing else like perfomance

    Regards


    Matelin

All Replies

  • Wednesday, November 04, 2009 8:45 PMNordine Ben Bachir Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Proposed Answer
    It's technically possible, but not recommended.  If you need a web service, create a new layer that internally calls Method1 and wrapper the result in a DataContract. You could use AutoMapper (http://automapper.codeplex.com/) to avoid boring mapping.


    Read Fredrik Normén 's blog post about putting your entities over the wire.
    http://weblogs.asp.net/fredriknormen/archive/2009/10/31/distributing-domain-entities-over-the-wire.aspx
    Nordine Ben Bachir
  • Sunday, November 08, 2009 5:36 PMMatelin Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi , i have read Fredrik Normén 's blog post and its really good one but i have one question :
    i intend to build a new n tier application contains of data access layer , business(domain) ,and presentation mainly,
    my presentation layer communicate to business directly(or thorough façade), 
    i want this application to be service ready in case i want to integrate with any party,
    so iam thinking of two options :
    1) Great a layer above my business layer that expose my DTO's ,so both third parties and my presentation layer use it.
    2) Create a stand alone application that expose DTO's to a third parties , and keep my business layer communicating with presentation layer .

    my opinion to use the second one coz service layer will effect performance , and no need to hide my domain from presentation layer what do u think???

    and one more thing for my personal knowledge 

    Quote "It's technically possible, but not recommended"

    Does it effect performance or not 

    Thank for your help

    Matelin