我正在使用MVC和WCF服务。我的MVC项目和WCF服务在同一个解决方案中。我在mvc项目和wcf服务项目中有相同的客户类。
我在服务返回List<Customer>
中编写了一个方法,我想在mvc项目中调用此方法但是我有一个错误,如&#34;无法将类型<x.Customer>
转换为<y.Customer>
&#34 ;
无论如何我改变了像Generic.List这样的服务引用配置,但是我有同样的错误。我该如何解决这个问题?
public class ReportService : IReportService
{
protected static List<Customer> Customers;
public List<Customer> GetReport(string Name,string Surname,string Address,string Phone) {
//NHibernate üzerinden select
Customers = new List<Customer>();
using (var session = NHibernateHelper.OpenSession())
{
using (var transaction = session.BeginTransaction())
{
var results = from c in session.Query<Customer>()
select c;
foreach (var result in results)
{
Customer customer = new Customer
{
CustomerId = result.CustomerId,
Name = result.Name,
Surname = result.Surname,
Address = result.Address,
Phone = result.Phone
};
Customers.Add(customer);
}
if (Customers.Count>0)
{
return Customers;
}
else
{
return null;
}
}
}
}
MVC代码:
ServiceReport.ReportServiceClient service = new ServiceReport.ReportServiceClient();
List<Customer> list = new List<Customer>();
list = service.GetReport(Name, Surname, Address, Phone);