WebMethod with Data Model

2

Good morning, I would like to receive a data model in a method from my webservice, what is the correct procedure for me to get it? I'm trying the code below but it's not working.

namespace UI.Web
{
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]

    public class Services : System.Web.Services.WebService
    {

        private string ChaveSeguranca = "";

        private BancoContexto contexto;

        public Services()
        {
            contexto = new BancoContexto();
        }

        [WebMethod]
        public string ControleUsuario(Farmacia Farma)
        {
            return "Ok";
        }
    }

}

Error:

  

Can not serialize member   Application.Core.Dominio.Farmacia.Treinamentos of the type   System.Collections.Generic.ICollection'1 [[Application.Core.Domain.Farmacy.Training,   Aplicacao.Core, Version = 1.0.0.0, Culture = neutral,   PublicKeyToken = null]] because it is an interface.

    
asked by anonymous 17.12.2015 / 14:14

1 answer

2

You should have something like this:

public class Farmacia 
{
    ...

    public ICollection<FarmaciaTreinamento> Treinamentos { get; set; }
}

Switch to:

public class Farmacia 
{
    ...

    public List<FarmaciaTreinamento> Treinamentos { get; set; }
}
    
17.12.2015 / 14:41