First of all, I'm a new developer, so I apologize in advance if I'm missing something obvious.
I'm developing a web application to work offline with large amounts of data in an IndexedDB. When the user goes to the webapp, the client grabs the entire database from the server and stores it for use in the indexeddb. That works fine, but when I'm trying to use a post method to send the data (again multiple records) back to WCF, I get method not allowed or bad request when trying to send an ajax body parameter, and when I do use uri parameters, it hits the server, but not all the data is sent. I thought perhaps invalid characters may be a factor so I used the encodeURIComponent method in javascript to convert invalid characters to be valid in a uri parameter. I've also tried compressing the data with a javascript compression api called LZString. I've tried using XMLHttpRequest(which I don't fully understand). This webapp has to work offline so I can't make a server call except for initially getting data when the client first opens and for syncing data back to the server, which is why I have to send large amounts of data at a time.
I'm also using an IndexedDB wrapper called Dexie.js.
Samples of my code is below. Some code is commented, but is left to show what I've tried.
This is what I have on the server..
[OperationContract]
[WebInvoke(Method = "POST",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "REST_SendCompletedServiceOrders",
BodyStyle = WebMessageBodyStyle.Wrapped)]
[FaultContract(typeof (Exception))]
bool REST_SendCompletedServiceOrders(string compressedWebData);
This is the click event on the client used to sync back..
$('#syncCompletedData').on('click', function() {
db.ServiceOrder
.toArray(function(so) {
var completedServiceOrders = [];
for (var i = 0; i < so.length; i++) {
if (so[i].IsCompleted) {
completedServiceOrders.push(so[i]);
};
}
var customerId = sessionStorage.getItem("customerId");
var companyId = sessionStorage.getItem("companyId");
var computerId = sessionStorage.getItem("computerId");
var webData = JSON.stringify({ webCustomerId: customerId, webCompanyId: companyId, webComputerId: computerId, webServiceOrder: completedServiceOrders });
alert(webData);
alert("before compression is " + webData.length);
var URIEncodedWebData = encodeURIComponent(webData);
var JSONWebData = JSON.stringify(URIEncodedWebData);
var compressedWebData = LZString.compressToUTF16(JSONWebData);
alert("after compression is " + compressedWebData.length);
debugger;
try {
$.ajax({
type: "POST",
url: "MFSRemoteDataService/REST_SendCompletedServiceOrders",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: { compressedWebData: compressedWebData },
success: function(data) { alert(JSON.stringify(data)); },
failure: function(errMsg) {
alert(errMsg);
}
});
} catch (e) {
alert(e);
}
});
});
Before compression data length is 7707. After compression data length is 1831.
Thanks in advance for any help, feedback, criticism, etc..