You could define a class containing only the fields you want to expose to use as return type for the service, and use Automapper to automatically generate an instance of the stripped-down class from a Pedido
instance.
How to send a subset of POCO data object to Client WCF
-
18-06-2023 - |
Вопрос
I'm building an n-tier application and using this class to comunícate server side layers(DAL Layer -> BusinessLayer Layer -> WCF Service Layer:
public class Ohmio: IOhmioService
{
public IEnumerable<Pedidos> Pedidos_Listar()
{
using (var context = new OhmioEntities())
{
var query =
from Pedidos in context.Pedidos
select Pedidos;
query = query.Where(i => i.ID_Cliente == 25);
return query.ToList();
}
}
}
The class expose an POCOs object to share between layers. This is ok for server side layers, but i need to control de info exposed on WCF Service. In WCF service layer, I use this class to expose the data to WCF client:
public class Ohmio : IOhmioService
{
public IEnumerable<Pedidos> Pedidos_Listar()
{
BusinessLayer.Ohmio _pedidos = new BusinessLayer.Ohmio();
return _pedidos.Pedidos_Listar();
}
}
My question: Can i expose only a sub-set of POCOs class field to WCF client instead of the whole object Pedido. I need to specify field to be exposed to WCF Client. Thanks!
Решение
Другие советы
Only decorate those properties of the POCO class with the DataMember
attribute that you want to be exposed to the WCF client.
Не связан с StackOverflow