I am using Microsoft Sync Framework to sync the details from the Datadictionary on android device with SQL Server. Initially get success to sync all data from sql server. But after adding some data and when clicking on the Sync button getting the following error. Can you please tell me is anybody came across this?
[Sync Error]:Error occurs during sync. Please check logs below.
[Upload Change Response Error]: 500 Response: <ServiceError xmlns="http://schemas.datacontract.org/2004/07/Microsoft.Synchronization.Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><ErrorDescription>System.InvalidOperationException
serverBlob is empty
at Microsoft.Synchronization.Services.SqlProvider.SqlSyncProviderService.ApplyChanges(Byte[] serverBlob, List`1 entities)
at Microsoft.Synchronization.Services.UploadChangesRequestProcessor.ProcessRequest(Request incomingRequest)
at Microsoft.Synchronization.Services.SyncService`1.ProcessRequestForMessage(Stream messageBody)
</ErrorDescription></ServiceError>
In the below code, i'm getting xmlHttp.status=500 when clicking on the Sync button
this.sendRequest = function (serviceUri, successCallback, errorCallback, dir) {
TraceObj("[" + dir + " Request]:", serviceUri, this.dataObject());
// Construct HTTP POST request
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("POST", serviceUri);
xmlHttp.setRequestHeader("Accept", "application/json");
xmlHttp.setRequestHeader("Content-Type", "application/json");
// Handle success & error response from server and then callback
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
var res = new SyncFormatter();
if (res.parse(xmlHttp.responseText)) {
TraceObj("[" + dir + " Response]:", serviceUri, res.dataObject());
alert("[" + dir + " Response]:", serviceUri, res.dataObject());
successCallback(res);
return;
}
}
TraceMsg("[" + dir + " Response Error]: ", xmlHttp.status + " Response: " + xmlHttp.responseText);
errorCallback(xmlHttp.responseText);
}
};
xmlHttp.send(this.toString());
};
}
I have found the root cause of the problem. That is when i get the values from datadictionary storage, value has the single quotes in the values so not able to load the values in webview. Now i have replaced single quotes by \'. Now working fine.
Related
Hello i'm in trouble with angular HTTPclient.
I'm using Ionic 3 and Cordova so i cant use JQuery, that's why i use HTTPClient.
I have the following lines in my code :
var body = new URLSearchParams();
body.set('base64', this.getBase64Image(this.image));
body.set('x_poisson', "" + 0);
body.set('y_poisson', "" + 0);
body.set('x_gabarit', "" + this.points[this.points.length - 2]);
body.set('y_gabarit', "" + this.points[this.points.length - 1]);
body.set('largeur_image', "" + this.image.width);
body.set('hauteur_image', "" + this.image.height);
body.set('pseudo', pseudo);
var url = UrlServeur + "/index.php?module=Homologation&action=traiterPhotoApplication&listeCoin=" + corners;
console.log("[LOG][HOMO] Requesting on url: " + url);
this.http.post(url, body).subscribe(response => {
console.log("[LOG][HOMO] Homologation response: " + response);
loading.dismiss();
}, err => {
console.log(`[ERR][HOMO] Homologation error: (${err.status}) ${err.error}`);
loading.dismiss();
});
The probleme is that HTTPClient considere all response as error and i'm unable to get the body when i'm supposed to recieve a JSON.
Here are the log i have :
[17:09:59] console.log: [LOG][HOMO] Requesting on url:
http://X.XXX.XX.XXX/cdp/index.php?module=Homologation&action=traiterPhotoApplication&listeCoin=XXX,XXX,XXX,XXX,XXXX,XXX,XXXX,XXXX
[17:10:28] console.log: [ERR][HOMO] Homologation error: (0) undefined
When i watch on the logs of the serve X.XXX.XX.XXX it look like everything went well.
Thanks for reading, don't hesitate to ask for more informations.
Edit 1:
When i don't use an URLSearchParam the server don't get the post data event when manually setting post type to application/json manually
I tried with ResponseContentType as text :
var options = new RequestOptions();
options.responseType = ResponseContentType.Text;
this.http.post(url, body, options).subscribe(response => {
console.log(`[LOG][HOMO] Homologation response: ${response}`);
loading.dismiss();
}, err => {
console.log(`[ERR][HOMO] Homologation error: (${err.status}) [${err.error}] ${err}`);
loading.dismiss();
});
An i still get the following log : [ERR][HOMO] Homologation error: (0) [undefined] Response with status: 0 for URL: null
Edit 2:
It work when i build the app using ionic cordova build android --prod but not if i test using ionic cordova run android -lc
try send to post a simple obj (not a URLSearchParams)
var body:any = {
'base64':this.getBase64Image(this.image),
'x_poisson': "" + 0,
'y_poisson': "" + 0,
'x_gabarit': "" + this.points[this.points.length - 2],
'y_gabarit': "" + this.points[this.points.length - 1],
'largeur_image': "" + this.image.width,
'hauteur_image': "" + this.image.height,
'pseudo': pseudo
}
You also can try see if the response is "text" and not a json Object
this.http.post(url, body,{ responseType: 'text' })
I'm trying to get the http response headers every time I visit some site. I thought that using an observer like the following is enough to do it:
const OBS = Cc['#mozilla.org/observer-service;1'].getService(Ci.nsIObserverService);
let httpRequestObserver ={
observe: function(subject, topic, data){
var httpChannel = subject.QueryInterface(Ci.nsIHttpChannel);
if (topic == "http-on-examine-response") {
headers=httpChannel.getAllResponseHeaders();
}
}
};
And in the startup method I add it then in the shutdown I remove it:
OBS.addObserver(httpRequestObserver, "http-on-examine-response", false);//startup methode
OBS.addObserver(httpRequestObserver, "http-on-examine-response", false);//shutdown
But I'm getting this in the log:
JavaScript Error: "httpChannel.getAllResponseHeaders is not a function"
Am I taking the wrong way and the operation is more complicated than it seem? this is for an extension for firefox for android and i'm not using sdk. Thanks for your help.
nsIHttpChannel is not XMLHttpRequest. Instead XMLhttpRequest is a nice wrapper class around channels - not just http ones -, which also adds convenience functions such as getAllResponseHeaders().
You may use nsIHttpChannel.visitResponseHeaders to simulate getAllResponseHeaders.
if (subject instanceof Ci.nsIHttpChannel) {
var headers = "";
subject.visitResponseHeaders(function(header, value) {
headers += header + ": " + value + "\r\n";
});
}
I have followed the Microsoft Sync Framework tools and Tutorials.
http://code.msdn.microsoft.com/Sync-Framework-Toolkit-4dc10f0e
I am trying to use SQLite as my client database, for my server i have SQL Server 2008 R2, i provisioned my server database, and i was able to run an example with the browser cache for local storage. but i want to use SQLite database. when clicking on the "sync" button, the SQLite database in the Android devices should be synchronized with SQL Server database. Can you please guide me?
this.sendRequest = function (serviceUri, successCallback, errorCallback, dir) {
TraceObj("[" + dir + " Request]:", serviceUri, this.dataObject());
// Construct HTTP POST request
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("POST", serviceUri);
xmlHttp.setRequestHeader("Accept", "application/json");
xmlHttp.setRequestHeader("Content-Type", "application/json");
// Handle success & error response from server and then callback
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
var res = new SyncFormatter();
if (res.parse(xmlHttp.responseText)) {
TraceObj("[" + dir + " Response]:", serviceUri, res.dataObject());
alert("[" + dir + " Response]:", serviceUri, res.dataObject());
successCallback(res);
return;
}
}
TraceMsg("[" + dir + " Response Error]: ", xmlHttp.status + " Response: " + xmlHttp.responseText);
errorCallback(xmlHttp.responseText);
}
};
xmlHttp.send(this.toString());
};
}
In the above i'm getting xmlHttp.status is 500.
there is not out-of-the-box sync provider for SQLLite, so if you want to use that as your client database, you will have to build one by yourself.
If you have downloaded the Sync Framework Toolkit, you will find a sample sync provider for SQL CE that you can use to follow when writing your own SQLLite sync provider.
I have an AJAX function I am building which makes a call on scroll or click/touchtstart to append some content to my HTML. Everything works great for me in the desktop environment, both on click and on scroll events. However neither of them work on my Android 2.3.7 HTC EVO or my Nexus 7 on Android 4.1.1.
Here is my click JavaScript event handler:
$('.loadMore').each(function() {
//Set URL and start on the first page
var self = this;
var path2root = ".";
var loc = window.location.origin;
var url = loc + "/process.php";
var subcategoryId = $(this).parent().attr('data-subcategoryId');
var page = 1;
// Build the updated URL
$(self).bind('touchstart', function(e) {
e.preventDefault();
page++;
// AJAX function for processing JSON
$.ajax({
url: url + "?subcategoryId=" + subcategoryId + "&page=" + page,
type: "GET",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function (data) {
var i = 0;
for(i = 0 ; i < data.length; i++) {
var articleId = data[i].articleResult.articleId;
var title = data[i].articleResult.title;
var subhead = data[i].articleResult.subhead;
var image = data[i].articleResult.image;
var response = "<td><div class='articleResult'><a href='" + path2root + "/article/article.php?articleId=" + articleId + "'><img src='" + image + "' width='120'/></a><br><h3><a href='" + path2root + "/article/article.php?articleId=" + articleId + "'>" + title.substring(0,25) + "</a></h3></div></td>";
$("table tr td:nth-last-child(2)").after(response);
};
}
});
});
});
My scroll function is very similar, only I bind the event to a different element, and on scroll:
// Collecting scroll info
$('.overthrow').each(function() {
// SAME VARIABLES
$(this).scroll(function () {
if ($(self).scrollLeft() >= parseInt($(document).width() - 50)) {
if (finished == 1) {
page++;
finished = 0;
// SAME AJAX FUNCTION
};
};
});
});
Keep in mind this is a mobile optimized webpage, not a native PhoneGap app, and I am using regular jQuery 1.8.0, not jQuery Mobile or PhoneGap.
I had found THIS issue over on Google Code in regards to Android 2.3 not receiving touchstart events very effectively, which led me to start building the on scroll function instead.
According to your link from Google Code the fix would be to include an e.preventDefault() at the start of your touchstart event like so:
$(self).bind('touchstart', function(e) { // include e as a reference to the event
e.preventDefault(); // prevents the default behaviour on this element
....
});
The above works on my Android 2.X devices; I hope it helps!
So I was able to get the AJAX call functioning properly for the on scroll event. I have abandoned the click/touchstart event all together as that seems to be buggy in Android.
For whatever reason, Android was not reading dynamic URL correctly when uploaded to the webserver:
var loc = window.location.origin;
var url = loc + "/process.php";
So when I was building my ajax call with the compiled URL:
$.ajax({
url: url + "?subcategoryId=" + subcategoryId + "&page=" + page,
the window.origin.location was being misinterpreted. Instead I needed to hard-code the location of my process.php file:
url: "process.php?subcategoryId=" + subcategoryId + "&page=" + page,
I discovered my solution through another SO post HERE
The only catch being my code was working on iPhone, but not on Android. If anyone knows the reason behind this, that would be great information to have.
Phonegap Crew,
I have an problem with accessing a webservice using android. I have no problem accessing it using iOS.
The enclosed code uses a public webservice so you can try the code if you are so inclined.
On iOS we get a xmlhttp.status == 200 and returned data.
On Android we get a xmlhttp.status == 0.
We are using cordova-1.8.1.jar
We have the white list set in res/xml/cordova.xml
like this:
<access origin=".*"/>
I am bring that up because I am suspicious that our white list is not working.
here is the code:
function testweather(){
var xhr= new XMLHttpRequest();
xhr.onreadystatechange = function(){
alert(xhr.readyState);
if(xhr.readyState == 4){
if(xhr.status == 200){
$( "#result" ).append( xhr.responseText );
}
else{
alert("can't get response. a.status:"+xhr.status);
}
}
}
var url = "http://graphical.weather.gov/xml/SOAP_server/ndfdXMLserver.php";
xhr.open("POST", url,true);
xhr.setRequestHeader("SOAPAction", "http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl#NDFDgenByDayLatLonList");
xhr.setRequestHeader("Content-Type", "text/xml;charset=UTF-8");
xhr.setRequestHeader("Content-Length", 1536);
xhr.setRequestHeader("Access-Control-Allow-Origin", "*");
xhr.setRequestHeader("Accept", "application/soap+xml, application/dime, multipart/related, text/*");
xhr.setRequestHeader("User-Agent", "IBM Web Services Explorer");
xhr.setRequestHeader("Cache-Control", "no-cache");
xhr.setRequestHeader("Pragma", "no-cache");
xhr.setRequestHeader("Connection", "close");
var soapEnv = '' +
'<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ndf="http://graphical.weather.gov/xml/DWMLgen/wsdl/ndfdXML.wsdl">' +
' <soapenv:Header/>' +
' <soapenv:Body>' +
' <ndf:NDFDgenByDayLatLonList soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">' +
' <listLatLon xsi:type="dwml:listLatLonType" xmlns:dwml="http://graphical.weather.gov/xml/DWMLgen/schema/DWML.xsd">35.4,-97.6</listLatLon>' +
' <startDate xsi:type="xsd:date">2012-06-27</startDate>' +
' <numDays xsi:type="xsd:integer">3</numDays>' +
' <Unit xsi:type="dwml:unitType" xmlns:dwml="http://graphical.weather.gov/xml/DWMLgen/schema/DWML.xsd">e</Unit>' +
' <format xsi:type="dwml:formatType" xmlns:dwml="http://graphical.weather.gov/xml/DWMLgen/schema/DWML.xsd">24 hourly</format>' +
' </ndf:NDFDgenByDayLatLonList>' +
' </soapenv:Body>' +
'</soapenv:Envelope>';
xhr.send( soapEnv );
}
Sometimes when you do an AJAX request from the file protocol you will get a status of
0 but that is effectively a 200. Just change you if to be:
if(xhr.status == 200 || xhr.status == 0)
and you should be good to go.
Here is a blog post I wrote on using AJAX from PhoneGap.
http://simonmacdonald.blogspot.com/2011/12/on-third-day-of-phonegapping-getting.html
Updated: Apparently there is a bug in Android 2.x where setting the "Content-length" header causes the problem you describe. It looks like the bug has been fixed in Android 4.0.3. So try this code unmodified in the 4.0.3 emulator and it should work then come back to 2.x and remove the Content-length header to see if it works as well.
We gave up trying to run the webservice in Javascript and wrote a Java plugin to run the webservice. We needed it to work on a wide variety of devices and not rely on the user updating their device.
Try adding the below code in src > com.domain.appname > appname.java after
super.onCreate(savedInstanceState);
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}