Y
Y
Yuri Shcheglov2014-04-20 10:44:49
Software design
Yuri Shcheglov, 2014-04-20 10:44:49

How to organize the right architecture with a WCF service in a three-tier project?

Started learning WCF. For my test project, I decided to make a three-tier project: 1) a class library with all the business logic and work with the database on LinqToSql; 2) WCF service library; 3) ASP.NET MVC client.
Actually, the snag arose in how best to organize the LinqToSql - WCF connection.
At the moment, the interfaces of my LinqToSql models are:

interface IVisitor
    {
        DateTime DateOfBirth { get; set; }
        bool Gender { get; set; }
        string Name { get; set; }
        string Surname { get; set; }
        System.Data.Linq.EntitySet<Visit> Visit { get; set; }
    }

interface IVisit
    {
        DateTime DateVisit { get; set; }
        long IdVisitor { get; set; }
        Visitor Visitor { get; set; }
    }

what would be the best way to transfer these classes to a WCF project and declare [DataContract]s? Putting attributes directly in the business logic project will be a bad form, especially since you have to go into the dbml designer.
But would it be good to use these interfaces in the wcf service project to implement the classes VisitorDataContract, VisitDataContract and in the service implementation cast the model object into the object of this class? In fact, there will be code duplication.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anatoliy Mikhailov, 2014-10-13
@EpeTuK

It is better to make separate classes with the same fields as in the linq2sql models, and inside the service implementation from the data contract, copy the fields to the corresponding model, for example, via AutoMapper.

public class MyService{
public IEnuberable<SVisit > GetAllVisitors(){
return dc.Visits.ToList().Select(Mapper.Map<SVisit>);
}
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question