WCF service granularity

Anas TINA
Anas TINA used Ask the Experts™
on
I am developing an electronic medical record (EMR) system.

I am designing and implementing the backend APIs using WCF.

Now, I have two system actors: secretary and doctor.

I designed the services according to the actor he/she is concerned.

[ServiceContract]
public interface ISecretaryService
{
}

[ServiceContract]
public interface IDoctorService : ISecretaryService
{
//the doctor has the functions of secretary in case she was absent!
}

Open in new window


The problem is I have duplicate code which is the implementation of the ISecretary contract in doctor service.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
DarrenSenior Software Engineer

Commented:
Hi,

Can you use interface inheritance?

https://stackoverflow.com/questions/6955421/inheritance-of-contracts-in-wcf

Might help,

Darren

Author

Commented:
This information does not cover the depth that I need to solve my problem.

I need to know how to design my WCF services precisely.

As I post before, I have two system actors: secretary & doctor. I am designing the services according to the involved actor.

I can pass an ISecretary service object to the caller but how if the logged user is a doctor?

This returning me to the question title: granularity of WCF service. Should I design the service according to business entities I have? rather than the involved actor?

namespace ECMS.Client.Desktop.Presenters
{
    public class AddPatientPresenter : IAddPatientPresenter
    {
        private readonly IAddEditPatientView _view;
        public AddPatientPresenter(IAddEditPatientView view)
        {
            _view = view;

            SubscribeToEventsSetup();
        }

        private void SubscribeToEventsSetup()
        {
            _view.SaveBtnClickedEventHandler += OnSaveBtnClickedEventHandler;
        }

        private void OnSaveBtnClickedEventHandler(object sender, EventArgs eventArgs)
        {
            //Here I need to call the backend service!
        }

        public IAddEditPatientView GetView()
        {
            return _view;
        }
    }
}

Open in new window

Senior Software Engineer
Commented:
Hi,

In my opinion, Actors are usually users of the system and should be thought of in terms of authentication and authorisation.

The entities that read and write to the database would be Patient, Appointment, Prescription etc...  (these entities are just general)

The entities would have CRUD activities on them.

Then you would have a business layer, such as PatientManager->SavePatientDetails, AppointmentManager->Save/MakeAppointment etc...Each of these business classes might use one of more entities and you would also have business rules and validation. E.g. you might have an Email Manager or SMS Manager that would be called by AppointmentManager to send an email or SMS to the patient as a reminder.

Then you would have the service which would largely mirror the business later operations.

This is what I would expose to the outside world and the Doctor would have authorisation to perform all tasks and the Secretary would have authorisation to do only a few. In my opinion this authorisation checking should be done in the service implementation and then  Manager class is called to perform the specific task.

Hope this helps,

Darren

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial