Share an enum between ASMX Web Services
Asked Answered
C

2

7

I have a web service project with several web services. Two of this web services share an enum that is defined in a BL class, like so:

public class HumanResourcesService
{
    public SomeLibrary.Employee GetEmployee(int employeeCode)
    {
       var employee = new SomeLibrary.Employee();
       employee.Type= SomeLibrary.EmployeeType.SomeType;
       return employee ;
    }
}

public class BankService
{
    public bool ProcessPayment(int employeeCode, EmployeeType employeeType)
    {
        bool processed = false;
        // Boring code
        return processed;
    }
}

This is just an example.

Both web services, when referenced in a web project, generate a different EmployeeType enum proxies, so I need to cast explicitly to invoke the ProcessPayment method in BankService:

public void SomeMethod(int employeeCode)
{
     var hrService = new HumanResourcesService();
     var employee = hrService.GetEmployee(employeeCode);

     var bankService = new BankService();
     bankService.ProcessPayment(employee.Code, (MyProject.BankService.EmployeeType) employee.Type);
}

I understand .NET has to do this in order to create the WSDL, but can't I somehow make both services refer to the same enum on the proxy classes without breaking anything?

Charissacharisse answered 25/10, 2011 at 22:34 Comment(1)
Are you using WCF or ASP.NET?Phonics
E
3

You can use the sharetypes parameter of wsdl.exe. See http://msdn.microsoft.com/en-us/library/7h3ystb6.aspx for details.

Evieevil answered 5/11, 2011 at 17:41 Comment(0)
A
0

If you expose the same enum, the proxies will work fine:

public class BankService
{
    public bool ProcessPayment(int employeeCode, MyProject.BankService.EmployeeType employeeType)
    {
        bool processed = false;
        // Boring code
        return processed;
    }
}

public void SomeMethod(int employeeCode)
{
     var hrService = new HumanResourcesService();
     var employee = hrService.GetEmployee(employeeCode);

     var bankService = new BankService();
     bankService.ProcessPayment(employee.Code, employee.Type);
}
Allo answered 25/10, 2011 at 23:35 Comment(1)
I do expose the same enum, defined in a common library.Charissacharisse

© 2022 - 2024 — McMap. All rights reserved.