Pass the JSON array to the WCF web service

I am trying to pass a JSON array to a WCF service. But it doesn't seem to work. I actually pulled the [GetStudents] array from the service and sent the same array back to the [SaveStudents] service, and nothing (an empty array) was received. The JSON array has the format:

[
  {"Name":"John","Age":12},
  {"Name":"Jane","Age":11},
  {"Name":"Bill","Age":12}
]

And the contracts have the following format:

//Contracts
[DataContract]
public class Student{
  [DataMember]public string Name { get; set; }
  [DataMember]public int Age{ get; set; }
}

[CollectionDataContract(Namespace = "")]
public class Students : List<Student>
{
  [DataMember]public Endorsements() { }
  [DataMember]public Endorsements(IEnumerable<Student> source) : base(source) { }
}

//Operations
public Students GetStudents()
{
  var result = new Students();
  result.Add(new Student(){Name="John",12});
  result.Add(new Student(){Name="Jane",11});
  result.Add(new Student(){Name="Bill",12});
  return result;
}

//Operations
public void SaveStudents(Students list)
{
  Console.WriteLine(list.Count); //It always returns zero
}

Is there a way to send an array to a WCF REST service?

+3
source share
1 answer

. , , Firefox "application/json" "application-json; charset = utf-8". , non-firefox, ,

+1

Source: https://habr.com/ru/post/1739308/


All Articles