I use AJAX & WCF
and I want to send an array of KeyValuePair
:
Array that is in Service(that is in a particular class):
[DataMember]
public KeyValuePair<string, CustomDay>[] WorkDays { get; set; }
CustomDay.cs:
[DataContract]
public class CustomDay
{
[DataMember]
public CustomTime Start { get; set; }
[DataMember]
public CustomTime End { get; set; }
}
CustomTime.cs:
[DataContract]
public class CustomTime
{
[DataMember]
public int Hour { get; set; }
[DataMember]
public int Minute { get; set; }
}
I create the array in JavaScript
by the following function:
function CreateWorkDaysDictonary() {
var workdaysdic = new Object();
if ($('#checkbox-sunday').is(':checked')) {
var starttime = { Hour: $('#select-from-hour-sunday').val(),
Minute: $('#select-from-minute-sunday').val()
};
var endtime = { Hour: $('#select-until-hour-sunday').val(),
Minute: $('#select-until-minute-sunday').val()
};
workdaysdic["Sunday"] = { Start: starttime, End: endtime };
}
if ($('#checkbox-monday').is(':checked')) {
var starttime = { Hour: $('#select-from-hour-monday').val(),
Minute: $('#select-from-minute-monday').val()
};
var endtime = { Hour: $('#select-until-hour-monday').val(),
Minute: $('#select-until-minute-monday').val()
};
workdaysdic["Monday"] = { Start: starttime, End: endtime };
}
//and so on...
return workdaysdic;
}
Array created in JS
:
But to WCF
the array arrives without data:
I do not understand why this happens, I'll be happy with someone could help me.
I send the object to WCF as JSON
:
When I try to create the object liks this:
function CreateWorkDaysDictonary() {
var workdaysdic = new Array();
if ($('#checkbox-sunday').is(':checked')) {
var starttime = { Hour: $('#select-from-hour-sunday').val(),
Minute: $('#select-from-minute-sunday').val()
};
var endtime = { Hour: $('#select-until-hour-sunday').val(),
Minute: $('#select-until-minute-sunday').val()
};
workdaysdic[workdaysdic.length] = { "Sunday": { Start: starttime, End: endtime}};
}
if ($('#checkbox-monday').is(':checked')) {
var starttime = { Hour: $('#select-from-hour-monday').val(),
Minute: $('#select-from-minute-monday').val()
};
var endtime = { Hour: $('#select-until-hour-monday').val(),
Minute: $('#select-until-minute-monday').val()
};
workdaysdic[workdaysdic.length] = { "Monday": { Start: starttime, End: endtime} };
}
//and so on...
return workdaysdic;
}
I get error: the server responded with a status of 400 (Bad Request)