Search code examples
c#wcfserializationdatacontractserializer

Serialization error when calling WCF service


When I call the service I receive this error:

Element ListadoClientesResult from namespace tempuri.org cannot have child contents to be deserialized as an object. Please use XmlNode[] to deserialize this pattern of XML

The service code is:

public List<Empleado> ListarEmpleados()
{
    List<Empleado> returnList = new List<Empleado>();
    var lista = from u in DB.tabEmpleado
                select new
                {
                    u.idEmpleado,
                    u.idUsuario,
                    u.Nombre,
                    u.Apellidos,
                    u.Telefono1
                };                           
    foreach (var e in lista)
    {
        Empleado empleado = new Empleado();
        empleado.idEmpleado = e.idEmpleado;
        empleado.idUsuario = e.idUsuario;
        empleado.nombre = e.Nombre;
        empleado.apellidos = e.Apellidos;
        empleado.telefono1 = e.Telefono1;
        returnList.Add(empleado);                
    }
    return returnList;
}

And the class definition is this:

    [DataContract]
public class Empleado { 

private int _idEmpleado; 
[DataMember(IsRequired = false)] 
public int idEmpleado 
{ 
get { return _idEmpleado; } 
set { _idEmpleado = value; } 
}

private int _idUsuario;
[DataMember(IsRequired = false)]
public int idUsuario
{
    get { return _idUsuario; }
    set { _idUsuario = value; }
}

private string _nombre;
[DataMember(IsRequired = false)]
public string nombre
{
    get { return _nombre; }
    set { _nombre = value; }
}

private string _apellidos;
[DataMember(IsRequired = false)]
public string apellidos
{
    get { return _apellidos; }
    set { _apellidos = value; }
}

private string _telefono1;
[DataMember(IsRequired = false)]
public string telefono1
{
    get { return _telefono1; }
    set { _telefono1 = value; }
}
}

Here is the ServiceContract

   namespace MetodosNegocio
{
    [ServiceContract]
    public interface IService
    {
        [OperationContract]
        List<Empleado> ListadoClientes();
    }
}

How can I solve this problem?

Thanks in advance.


Solution

  • Any change made in a service is not applied until you update the service, so I updated it and it was working.