I need assistance in connecting a JavaScript application to a WCF service. The WCF Service I have includes the following method:
[OperationContract]
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, UriTemplate = "/ExportToXml")]
void ExportToXml(List<Span> spans, List<Detection> detections);
[DataContract]
public class Detection
{
[DataMember]
public int TID { get; set; }
[DataMember]
public double Longitude { get; set; }
[DataMember]
public double Latitude { get; set; }
[DataMember]
public double Height { get; set; }
[DataMember]
public int SN { get; set; }
[DataMember]
public string TLine_Name { get; set; }
}
[DataContract]
public class Span
{
[DataMember]
public int SN { get; set; }
[DataMember]
public double Longitude { get; set; }
[DataMember]
public double Latitude { get; set; }
[DataMember]
public string TLine_Name { get; set; }
}
However, I am struggling to format the JSON data correctly on the client-side to pass into this function using JavaScript. The JSON I prepared appears as follows:
var input = {
"spans": [{
"SN": 1,
"Longitude": 1000000,
"Latitude": 1000000,
"TLine_Name": "Circuit Test 1"
}, {
"SN": 2,
"Longitude": 2000000,
"Latitude": 2000000,
"TLine_Name": "Circuit Test 2"
}],
"detections": [{
"TID": 1,
"Longitude": 1000000,
"Latitude": 1000000,
"Height": 15,
"SN": 1,
"TLine_Name": "Circuit Test 1"
}, {
"TID": 2,
"Longitude": 1000000,
"Latitude": 1000000,
"Height": 12,
"SN": 1,
"TLine_Name": "Circuit Test 1"
}, {
"TID": 3,
"Longitude": 1000000,
"Latitude": 1000000,
"Height": 14,
"SN": 1,
"TLine_Name": "Circuit Test 1"
}, {
"TID": 4,
"Longitude": 1000000,
"Latitude": 1000000,
"Height": 10,
"SN": 2,
"TLine_Name": "Circuit Test 2"
}, {
"TID": 5,
"Longitude": 1000000,
"Latitude": 1000000,
"Height": 8,
"SN": 2,
"TLine_Name": "Circuit Test 2"
}]
};
The WCF service is not accepting the provided JSON input structure. Any guidance and support regarding this issue would be greatly appreciated.