locked
DomainModel to WCF conversion. RRS feed

  • Question


  • If you have an existing domain model, what is a best practise to move into WCF environment.
    Would you create one wcf service foreach domain object.
    For ex:
    If your object model has following classes:
    1. DomainObjectBase
    2. Customer: DomainObjectBase
    3. Order: DomainObjectBase
    4. Item: DomainObjectBase

    Customer has Orders
    and Order has Items.

    Methods in Customer may be addCust, removeCust, updateCustomer
    and in Order: addOrd, removeOrd, updateOrd.

    I would just like to get an idea as we r in the process of developing a prototype
    project in WCF. Will appreciate any suggestions.
    Thanks
    Thursday, August 23, 2007 10:30 PM

All replies

  • I think it depends on the purpose of the services.  If they are just to be used internally by your app, you could do something like what you mention--whatever makes the most sense to play well with your domain model and deployment constraints.  It might be as simple as marking your classes as data contracts and creating a few discrete operations to work on them.

     

    If you're planning on them being exposed to other applications, you need to think about the services' operations and data contracts from a standpoint of SOA, ensuring that you have explicit application boundaries, that your consumers don't need internal knowledge of your app/service for them to work, and all the other good stuff that generally goes along with that.  In short, the bar is higher for those, and you may need to rethink what operations you're exposing and perhaps do some custom serialization if needed (e.g., if your data contract is significantly different from your OM).  There is plenty of guidance available for designing service-oriented services using WCF that you should look into if that's the route you need to go (e.g., this).

    Thursday, August 23, 2007 11:10 PM
  • Thank you Ambrose.
    Friday, August 24, 2007 2:33 PM
  • I think if you want to use your domain model as a starting point to creating WCF services, the web services software factory can be found here this will be a great place to start.

     

    Saturday, August 25, 2007 7:51 PM
  • Think of it like this...

     

    Why are you exposing WCF services? How will they be consumed? As opposed to having a 1 to 1 relationship between your business objects and data contacts, why not use the WCF data contracts to wrap data from various business objects into 1 data contract, perhaps in terms of mapping a screen in the consuming application that displays customer data. Here you may wrap specific customer data from address, user and customer business objects to 1 data contract called CustomerView.

     

    Remember, data contracts can inherit other data contracts, using this can be very useful.

     

    In terms of programatically mapping business object data to data contracts, I'd suggest creating a Helper class which Takes a Business Object (perhaps a business object base class) and a Data Contract. The method uses reflection to map properties and populate data, then returns the populated DataContract for sending over the wire.

     

    Hope this helps

    Chris

    Monday, August 27, 2007 8:17 AM