0

I am new to WCF Services and can't get rid of this problem. For the next version of our web application I want to make use of WCF as webservice. Currently I am stuck with this problem:

To try WCF out I made 2 services: EmployeeService and AuthenticationService. I also made a datacontract Employee.

In AuthenticationService I use EmployeeService to get the logged Employee

Now in my client (ASP MVC Web) I add both Services as I need them both. But then when I try to use the object Employee I get the error :

Employee' is an ambiguous reference between 'IWA.Portal.AuthenticationService.Employee' and 'IWA.Portal.EmployeeService.Employee

The reason I want to make multiple services is to group them functionally. Example: Everything regarding employees will be under EmployeeService and everything regarding job will be under JobService.

How can I fix this or how should I structure my webservice?

Currently my webservice solution consists of :

  • Project.DataContracts (Entities)
  • Project.ServiceContracts (Interfaces)
  • Project.Services (Services, NHibernate & Castle Windsor)

Any help is much appreciated! Thx

AuthenticationService

public class AuthenticationService : IAuthenticationService
{
    private readonly IEmployeeService _employeeService;

    public AuthenticationService(IEmployeeService employeeService)
    {
        _employeeService = employeeService;
    }

    public Employee Authenticate()
    {
        var employee = _employeeService.Get(1);

        return employee;
    }
}

Code in my client (Controller)

    readonly EmployeeServiceClient _employeeService = new EmployeeServiceClient();
    readonly AuthenticationServiceClient _authenticationService = new AuthenticationServiceClient();

    Employee authedEmployee = _authenticationService.Authenticate();
    Employee test = _employeeService.Get(827);
Nanou Ponette
  • 1,372
  • 4
  • 22
  • 46

1 Answers1

0

Looks like your namespaces are clashing and to fix it you will need to use full names in your code when referring to a class so instead of just Employee use

AuthenticationService.Employee auth_emp = new AuthenticationService.Employee();

and

EmployeeService.Employee es_emp = new EmployeeService.Employee();

This will solve your problem.

Yuri
  • 2,820
  • 4
  • 28
  • 40
  • This will fix my error indeed but the object does not have the same meaning if I do this. – Nanou Ponette Dec 09 '15 at 14:33
  • In this case you should Have only one Employee class defined in your project and use it in both namespaces. You can pass an object from one namespace to another using dependency injection. Good start for you would be to read this post http://stackoverflow.com/questions/130794/what-is-dependency-injection – Yuri Dec 09 '15 at 14:35
  • I only have 1 employee class defined in my Project.DataContracts. I don't understand how DI can fix this. I am using DI to pass EmployeeService to my AuthenticationService . – Nanou Ponette Dec 09 '15 at 14:39
  • Can you post part of the code which generates the problem? – Yuri Dec 09 '15 at 14:42
  • So, why do you have two methods to return employee? – Yuri Dec 09 '15 at 14:52
  • Well this is just a code example but should I not be able to use the same entities in multiple services? This will happen for sure when I transfer all my code to the webservice. – Nanou Ponette Dec 09 '15 at 14:56
  • Yes, you can use same object in different namespaces, but best way to achieve it is DI. You need somebody to review your approach. – Yuri Dec 09 '15 at 15:11
  • 1
    I don't see how I can fix this with DI. However If I would place everything in one service then I would have no problem but then I lose my grouping. – Nanou Ponette Dec 10 '15 at 07:50