在ASMX Web服务之间共享一个枚举

我有一个Web服务项目与几个Web服务。 其中两个Web服务共享一个在BL类中定义的枚举,如下所示:

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;
    }
}

这只是一个例子。

这两个Web服务在web项目中引用时都会生成不同的EmployeeType枚举代​​理,因此我需要明确BankService以调用BankServiceProcessPayment方法:

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);
}

我知道.NET必须这样做才能创建WSDL,但是不能以某种方式使两种服务在代理类上引用相同的枚举而不会破坏任何东西?


您可以使用wsdl.exe的sharetypes参数。 有关详细信息,请参阅http://msdn.microsoft.com/en-us/library/7h3ystb6.aspx。


如果你公开相同的枚举,代理将正常工作:

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);
}
链接地址: http://www.djcxy.com/p/9873.html

上一篇: Share an enum between ASMX Web Services

下一篇: Way to determine true calling assembly