我有一个包含多个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
枚举代理,因此我需要显式转换以调用ProcessPayment
中的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);
}
我理解.NET必须这样做才能创建WSDL,但我不能以某种方式使两个服务在代理类上引用相同的枚举而不会破坏任何内容吗?
答案 0 :(得分:3)
您可以使用wsdl.exe的sharetypes参数。有关详细信息,请参阅http://msdn.microsoft.com/en-us/library/7h3ystb6.aspx。
答案 1 :(得分:0)
如果您公开相同的枚举,代理将正常工作:
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);
}