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:
[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) { }
}
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;
}
public void SaveStudents(Students list)
{
Console.WriteLine(list.Count);
}
Is there a way to send an array to a WCF REST service?
source
share