Ask a questionAsk a question
 

AnswerEDM POCO x WebService

  • Friday, November 06, 2009 2:05 PMJulioNET Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    This is my source code of my class in EDM:

    public class People
    {
        public virtual int Id { get; set; }
        public virtual string FirstName { get; set; }
        public virtual string LastName { get; set; }
    }

    This is my source code of my web service:

    public

     

     

    class PeopleWS : System.Web.Services.WebService
    {
        [WebMethod]
        public List<Sistema> SelectPeoples()
        {
            MyContext db = new MyContext();
            return (from q in db.People select q).ToList();
        }
    }

    When I execute the web service this error is returned:
    System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: The type System.Data.Entity.DynamicProxies.People_09C9616929F8A9A58DFD553684CF043860C1241DFD5E18195F34AFC1D05275B1 was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.

    How do I solve this problem?

Answers

  • Friday, November 06, 2009 7:10 PMDiego B VegaMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi Julio,

    WCF serialization is not supported with POCO proxy types in beta 2. There is an explanation about this in the readme file. There is a workaround but it is relatively complicated and requires the definition of a DataContractResolver. I don't have the code at hand. In the meanwhile the recommendation is to disable proxies when creating objects that are going to be serialized. You can do this in ContextOptions.ProxyCreationEnabled = false.

    Hope this helps,
    Diego
    This posting is provided "AS IS" with no warranties, and confers no rights.

All Replies

  • Friday, November 06, 2009 7:10 PMDiego B VegaMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi Julio,

    WCF serialization is not supported with POCO proxy types in beta 2. There is an explanation about this in the readme file. There is a workaround but it is relatively complicated and requires the definition of a DataContractResolver. I don't have the code at hand. In the meanwhile the recommendation is to disable proxies when creating objects that are going to be serialized. You can do this in ContextOptions.ProxyCreationEnabled = false.

    Hope this helps,
    Diego
    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Friday, November 06, 2009 8:00 PMJulioNET Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Diego, thank you very much! Perfect!