none
Fill List<> Wcf serviceParameter do not have Add method RRS feed

  • Question

  • Hi,

    I have a a WCF service like this

     [OperationContract]
    void Insert(List<PersonList> person);
     [DataContract]
        public class PersonList
        {
            [DataMember]
            public List<Person> Persons{ get; set; }

        }
         [DataContract]
         public class Person
         {
             [DataMember]
             public  string Name
         }

    From the client I want to Fill PersonList, I have

    PersonList per = new PersonList();
    Person pp = new person();
    pp.Name = "aaa";
    per.Persons.Add(pp);

    .ADD Method Does not Exists?
    What I am missing?


    Diego

    • Moved by Barry Wang Friday, November 29, 2013 8:23 AM WCF related
    Thursday, November 28, 2013 8:15 PM

Answers

All replies

  • Hi,

    I have a WCF that looks like this

    [OperationContract]
    void Insert(List<Person> person);

     [DataContract]
     public class Person
         {
             [DataMember]
             public  string Name
             { get; set; }
             [DataMember]
             public  string LastName
             { get; set; }
         }

    From Client I made a reference to WCF and work fine. I have defined a list<Person> as

    List<Person> pp = new List<Person>();

    But when i make the call

    WCFClient.Insert(pp);

    Have an error type..

    How I have to define to allow passing list<> to Wcf Methods?

    Im working with Framework 4.5

    Thanks


    Diego

    Thursday, November 28, 2013 7:06 PM
  • Hi Diego,

    For more complex types (and obviously a List<T> is more complex), you need to add one more attribute after the [DataMember]:

    [DataMember]
    [System.Xml.Serialization.XmlElementAttribute("Persons")]
    public List<Person> Persons{ get; set; }


    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Thursday, November 28, 2013 9:00 PM
    Moderator
  • Hi Diego,

    Your issue is related to WCF technology so I've moved it to the right forum.

    Regards,



    Barry Wang
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, November 29, 2013 8:25 AM