Results 1 to 4 of 4

Thread: nTier question on WCF Service

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Location
    Wisconsin
    Posts
    788

    nTier question on WCF Service

    I have two classes (Service1.cs and IService1.cs) in a WCF project.
    Do I think of these as the Business Logic Layer or only as a passthrough to access the BLL, DLL, etc.? Also I think that there will a large number of functions in the BLL, is there a limit to the number of DataContracts or OperationContracts?
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;
    using System.Data;
    
    namespace SomeServer4._1
    {
        public class Service1 : IService1
        {
            public String Test()
            {
                return "HELLO";
            }
    
            public string GetData(int value)
            {
                return string.Format("You entered: {0}", value);
            }
    
            public CompositeType GetDataUsingDataContract(CompositeType composite)
            {
                if (composite == null)
                {
                    throw new ArgumentNullException("composite");
                }
                if (composite.BoolValue)
                {
                    composite.StringValue += "Suffix";
                }
                return composite;
            }
    
            public DataSet GetAPMF(String Company)
            {
                DataSet ds = new DataSet();
                return ds;
            }
        }
    }
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;
    using System.Data;
    
    namespace SomeServer4._1
    {
        [ServiceContract]
        public interface IService1
        {
            [OperationContract]
            String Test();
    
            [OperationContract]
            string GetData(int value);
    
            [OperationContract]
            CompositeType GetDataUsingDataContract(CompositeType composite);
    
            [OperationContract]
            DataSet GetAPMF(String Company);
            // TODO: Add your service operations here
        }
    
        // Use a data contract as illustrated in the sample below to add composite types to service operations
        [DataContract(Name="SomeDataContract")] 
        public class CompositeType : IExtensibleDataObject
        {
            private ExtensionDataObject extensionDataObjectValue;
            public ExtensionDataObject ExtensionData
            {
                get
                {
                    return extensionDataObjectValue;
                }
                set
                {
                    extensionDataObjectValue = value;
                }
            }
    
            bool boolValue = true;
            string stringValue = "Hello ";
    
            [DataMember]
            public bool BoolValue
            {
                get { return boolValue; }
                set { boolValue = value; }
            }
    
            [DataMember]
            public string StringValue
            {
                get { return stringValue; }
                set { stringValue = value; }
            }
        }
    }

  2. #2
    Hyperactive Member
    Join Date
    Jan 2010
    Posts
    259

    Re: nTier question on WCF Service

    You can use them as either.

    There is nothing wrong with having the BLL and DLL encapsulated in services. It makes the application more modular and it is much easier to switch out the service then having to chancge anything on a client. If you only wanted one service though, I would recommend it as a BLL that validates and passes it off to the DAL. Just for the fact the data should be validated before it ever touches the DAL.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2005
    Location
    Wisconsin
    Posts
    788

    Re: nTier question on WCF Service

    So...Service1.cs is a passthrough to the BLL? At this 'tier' am I only setting up DataContracts and the corresponding function calls?

  4. #4
    Hyperactive Member
    Join Date
    Jan 2010
    Posts
    259

    Re: nTier question on WCF Service

    A DataContract is just an understanding of an object type that could be sent. If you wanted to pass a class object through the service, you would need a data contract, otherwise the other end won't know how to handle the complex type as it only really understands primative types. It really is just a way of serializing the data.

    The service can be a pass-through OR the BLL itself. That implementation is up to you. Having the service pass whatever it received to the BLL would prompt looser coupling of the components. You will have to set up DataContracts and the functions that consume them in the service now otherwise a service that doesn't have methods or doesn't understand what is being sent isn't very useful.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width