Question

I have been developing a WCF service for my project. I have multiple projects in my solution, explained below:

  1. WCF Service - WCF Service Project
  2. Business Logic - project contains domain logic
  3. Data Access Layer - for accessing data
  4. Core - project contains the business objects only (Many of them are sent as a response of service call - This contains the classes which are to be shared with client)
  5. Log - project to log errors and activities

Service project puts call to Business project for the respective operation and the Business Logic project intializes the objects of the classes defined in Core object. And these objects are sent as the response of service call.

This is done successfully, i am able to share all public properties of the class defined in Core project. But i am unable to use DataContract/DataMember attributes in the core project as this is a non-WCF project. I need to achieve few tasks for which i have to use DataMember attributes like i dont want to share a property in case of null value, i don't want to share few properties of some objects with the client.

Please tell me if i am mistaken with the approach. And please help me achieving the above, i couldn't find any similar question on the forum.

Edit: (Let me try explaining it better)

All the projects are referenced in the WCF Service Project which consumes those project. This was to keep logical separation.

For Example, The Core project contains a class named User and this class is the return type of a service api. When this API is called, the logic initializes an object of User. And the object is returned as a result to that call.

In this case, i haven't used any [DataContract] attribute for the User class. And it works fine. Now i want to stop sharing few properties of this class, for this i needed to use [DataContract]/[DataMember] attributes, which are not being resolved in the Core project.

Was it helpful?

Solution

Ok, let me start by pointing out that data contracts and data members are not directly related to WCF. Actually, these attributes reside in a namespace that has nothing to do with services directly...theyre rather related to serialization and it's just a matter of adding a reference to the required assembly...i think it's System.Runtime.Serialization. I don't see why you can't add a reference to this assembly in your project.

The second question related to "hiding" members...i dont think you have to many options here. If you decorate a property with the DataMember attribute it will be serialized with the data contract, so there's no way you can't "hide" it. At best, what you can do is not to decorate a property with the DataMember attribute, but in this case the property will not be serialized, in other words, it will be ignored during the serialization process.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top