Reputation: 672
I have wcf service which is responsible for database interaction and business logic. it also has class library for business objects. i want wcf service to return List of objects. should i have to create another class lib of business objects for my asp .net project(which is consuming service) so that asp .net project can understand the object types?
Upvotes: 0
Views: 794
Reputation: 1714
Standard practice with services is to return DTOs instead of business objects: using your business objects in the presentation layer is going to tightly couple it to the business logic, and most of the time you don't want this sort of coupling. Also bear in mind that everything that you send on the wire should be serializable, and your business objects may or may not be serializable.
So I would say that yes, you most probably want to create a different library with DTOs and use the classes inside it as data contracts. The duplication is not really a problem, since it guarantees a certain stability of the contract and it is possible to map your business objects to DTOs with tools like AutoMapper.
Let us consider the advantages and disadvantages of the approach of having a common business class library shared between presentation (ASP.NET) and service layer.
Pros:
Cons:
Compare this to the creation of a DTO library:
Pros:
Cons:
Upvotes: 1
Reputation: 6862
You should share the class object library between the service and the asp.net project. That would be like 'middleware' for your whole project. That would avoid unnecessary duplication. Basically, just move all business objects to a different project and include it into both wcf and asp.net solutions.
Upvotes: 2
Reputation: 223307
Not really. When you will add the reference to web service using Add Service Reference via visual studio, you will get proxy classes for every object to be used in the web service
Upvotes: 1