A question on wcf and composite objects
-
This is my scenario: I have a huge database and I'm building numerous services to access the data. Each service exposes a unique set of data and services to the consumer. So for an object such as Company our internal service needs the raw address in the composite. However our portal service need fully enumerated Address info in the composite. I wanted to avoid having a massive object with various composite addon's that don't apply to a given object but I'm running into difficulties. First I decided that each composite builder class will be in a namespace deeper than the data namespace. So instead of myApp.Data it would be myApp.Data.Mainservice and myApp.Data.Portalservice for the composite objects. My next step was to inherit Company, add a constructure that takes Company as input to populate internal fields, and add the DataMember for each Composite that is needed. Works great but I get a runtime error that I cannot inherit an object that is not marked as Serializable or DataContract. Initially I just added a public partial class Customer and added the DataContract attribute, but that does not expose the DataMembers inside of the object. I also cannot use the partial class definition as I need to be inside the namespace of the Customer object which puts me back into the same problem of having an accumulation of composite objects. For those who need pictures here is the code I want to implement:
namespace Company.Data.InternalServices { \[DataContract\] public sealed class CompositeLocation : Company.Data.Location { \[DataMember\] public Address LocationAddress{get;set;} } \[ServiceContract\] public class InternalContract:IInternalContract { \[OperationContract\] public CompositeLocation GetLocation( Guid LocationIdentity ); } } namespace Company.Data.Portal { \[DataContract\] public sealed class CompositeLocation:Location { \[DataMember\] public EnumeratedAddress{get;set;} } \[ServiceContract\] public class PortalContract:IPortalContract { \[OperationContract\] public CompositeLocation GetLocation(Guid LocationIdentity); } }
When no method returns a Location, WCF drops the DataContract for Location. I want to force it to keep Lo