Webmethod with Data Model

Asked

Viewed 162 times

2

Good morning, I would like to receive a data model in a method of my webservice, what is the correct procedure for me to get ? 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:

Unable to serialize the member Application.Core.Domain.Farmacia.Training of the type System.Collections.Generic.Icollection`1[Application.Core.Domain.Farmaciatreineing, Application.Core, Version=1.0.0.0, Culture=neutral, Publickeytoken=null]] because it is an interface.

1 answer

2


You must have something like this:

public class Farmacia 
{
    ...

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

Change to:

public class Farmacia 
{
    ...

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.