我有一个wcf服务,我想要返回一个dto对象,然后我想从使用WSDL引用服务的其他应用程序web asp.net使用服务,但不能在dto客户端应用程序中从wcf工作dto。如何从WCF C#中返回DTO对象?
,并出示此错误:
Cannot implicitly convert type 'ClientApp.ClientWs.Client' to 'CoreApp.DTO.Client
而且DTO “客户” 是在这两个应用程序
DTO
public class Client
{
public string status { get; set; }
public string message { get; set; }
public List<Sales> listSales { get; set; }
public Client()
{
listSales = new List<Sales>();
}
}
WCF服务的相同:
public Client getClientByID(string id)
{
List<Sales> list = null;
Client clientResponse = null;
try
{
list = new List<Sales>();
list = bll.getInstance.listSales(id);
clientResponse = new Client();
clientResponse.status = "ok";
clientResponse.message = "success";
foreach (var item in list)
{
clientResponse.listSales.Add(item);
}
}
catch (Exception ex)
{
clientResponse = new Client();
clientResponse.status = "error";
clientResponse.message = ex.Message;
}
return clientResponse;
}
方法应用程序客户端T:
public static List<Sales> getByIdWebService(string id)
{
List<Sales> list = null;
ClientWs.ClientWsClient ws = new ClientWs.ClientWsClient;
Client response = new Client();
response = ws.getClientByID(id); //show error
if (response.status == "error")
{
throw new Exception(response.message);
}
else
{
list = new List<Sales>();
list = response.listSales();
}
}
你能在这里展示你的'Sales'类属性。 –