2011-10-25 110 views
7

我有一個包含多個Web服務的Web服務項目。這個Web服務兩股即在BL類中定義的,像這樣的枚舉:在ASMX Web服務之間共享一個枚舉

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枚舉代理,所以我需要顯式轉換來調用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,但是不能以某種方式讓這兩個服務在代理類上引用相同的枚舉而不破壞任何東西?

+0

您使用的是WCF還是ASP.NET? –

+0

我正在使用ASP.NET。 – Meryovi

回答

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

我確實公開了在公共庫中定義的相同枚舉。 – Meryovi