我有一個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'類屬性。 –