locked
Architecture question RRS feed

  • Question

  • I have a business object project. I want to create a WCF service so I can expose my business objects and their methods etc. I am a bit confused how I would do this since I need to create an interface and a service class. How do I accomplish exposing all of my business object through a service. None of the samples I have found explore this. They all show watered down samples.

    Wednesday, April 25, 2012 8:45 PM

All replies

  • On 4/25/2012 4:45 PM, velocetti wrote:
    > I have a business object project. I want to create a WCF service so I
    > can expose my business objects and their methods etc. I am a bit
    > confused how I would do this since I need to create an interface and a
    > service class. How do I accomplish exposing all of my business object
    > through a service. None of the samples I have found explore this. They
    > all show watered down samples.
    >
     
    Well your Business Objects should being implementing an Interface for
    each Business Object
     
    The WCF service would set reference to the BLL and use it through the
    implementations of the Business Objects Interfaces.
     
    Wednesday, April 25, 2012 8:55 PM
  • Your question is not clear.

    In general you have to exchange ad-hoc classes called DTO http://martinfowler.com/eaaCatalog/dataTransferObject.html.

    This because each service must expose the exact data needed to the consumers, no more no less.


    Matteo Migliore

    Bloghttp://blogs.ugidotnet.org/matteomigliore
    Twitterhttp://twitter.com/matteomigliore
    CodePlex

    Wednesday, April 25, 2012 8:59 PM
  • I don't understand why I would need to have an interface for every business object, unless its good practice.

    I currently do the following:

    BOL - Business object definition properties..

    BLL - business logic

    DAL - data access

    So you are saying create an interface for each class and implement this into my each BLL class and individual SVC file?

    Monday, April 30, 2012 8:55 PM
  • You need the interface since that will act as a contract for the service.

    This is one way you can quickly WCF-enable your service.

    1. Extract an interface out of your class. Mark all the interface methods with the OperationContract attribute. Mark the interface with the ServiceContract Attribute.

    2. Mark all the in and out parameter classes with the DataContract attribute and the members with the DataMember attributes. Ensure the properties have the getters and setters defined.

    3. Implement the interface. Make the implementing class implement the interface(service Contract).

    4. Create a .svc file that defines the service and augment it with the correct configuration file(web.config), if you plan to host it in IIS. There are multiple ways to host a WCF service.

    Monday, April 30, 2012 9:09 PM
  • I understand how to decorate the interface but is my method of creating the WCF service will classes correct. Thanks for help.

    BOL - Business object definition properties..

    BLL - business logic

    DAL - data access

    Create an interface for each class and implement the interface into each class and service file?

    Monday, April 30, 2012 11:07 PM
  • This depends. If you want to use a single service to expose all business objects, then you just need a single service interface. Inside the interface, you can define multiple operation contracts that return different business objects. But you can also use multiple services. In general, you can put related business objects in the same service, while put unrelated business objects in separate services.

    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    If you have feedback about forum business, please contact msdnmg@microsoft.com. But please do not ask technical questions in the email.

    Wednesday, May 2, 2012 9:37 AM
  • Your layers are fine, but as a good practice, we add a service layer on top of the BLL, just to take away the service related plumbing out of the BLL. We create an interface out of the service class and use that as the contract.
    Wednesday, May 2, 2012 7:45 PM
  • On 4/30/2012 4:55 PM, velocetti wrote:
    > I don't understand why I would need to have an interface for every
    > business object, unless its good practice.
    >
    > I currently do the following:
    >
    > BOL - Business object definition properties..
    >
    > BLL - business logic
    >
    > DAL - data access
    >
    > So you are saying create an interface for each class and implement this
    > into my each BLL class and individual SVC file?
    >
     
    Sorry, I have been in the hospital for the the last few days, just got
    out this past Tuesday.
     
    You have interfaces so that things are unit testable by mocking out
    objects that use an interface.
     
    No, I am not saying you have a SVC for each Business object. Your WCF
    service project has a reference to the  Business Layer that contains all
    of the Business objects. All the WCF service can do is call methods that
    have been implemented on a Business object interface. Of course you
    would not send the Business object through WCF, but instead you would
    send DTO(s) through WCF.
     You can go in two ways.
     
    BLL
    Service Layer
    WCF service
    DAL
     
    OR
     
    Service Layer
    WCF service
    BLL
    DAL
     
    Wednesday, May 2, 2012 9:01 PM
  • On 4/30/2012 7:07 PM, velocetti wrote:
    > I understand how to decorate the interface but is my method of creating
    > the WCF service will classes correct. Thanks for help.
    >
    > BOL - Business object definition properties..
     
    BOL? What is that?
     
    >
    > BLL - business logic
    >
    > DAL - data access
    >
    > Create an interface for each class and implement the interface into each
    > class and service file?
    >
     
    The SVC uses the interfaces on the BLL objects, and the iService.cs
    should be pointing to the methods that have been implemented on the
    Business Object.
     
    Wednesday, May 2, 2012 9:05 PM
  • Check contract first development: http://msdn.microsoft.com/en-us/magazine/ee335699.aspx

    IMHO i always structure my WCF solution into these:

    WCF Solution

          ---> Contract (Class Library), contains Service Contracts/Service Interface and Data/Message Contracts

         ---> Service (Class Library)

                   -> BusinessEntities = you can opt for additional layer, but you need to convert from BE to Data Contracts and vice-versa.

                   -> BusinessComponents = this is where you execute business rules/objects, for simplicity sake it will return a BusinessEntity or directly a Message/Data

                        contract.

                   -> Data Components = Repository Pattern (One for Test so i can mockup data and one that uses EF Entity Framework to retreive data from db.)

                   -> Data Entities = Contains the Entity Framework model

                   -> Service Agents = Only needed if you need to call other Service

                   -> ServiceImplementation = Implementation of Service Contract/Service Interface, calls the Business Components from here.

         ---> Proxies (Class Library), returns a proxy client, to be distribute to clients together with the contract library.

         ---> Host (WCF Service Application), references the service and only contains the .svc file which service is equal to the Service Implementation.

                 Only used to generate a zip file that you can import thru IIS and automate installation using powershell.

         ---> UnitTest (Test Project)


    Randy Aldrich Paulo

    MCTS(BizTalk 2010/2006,WCF NET4.0), MCPD | My Blog


    BizTalk Message Archiving - SQL and File
    Automating/Silent Installation of BizTalk Deployment Framework using Powershell >
    Sending IDOCs using SSIS



    Thursday, May 3, 2012 5:39 AM