PDA

View Full Version : How can I access webservice using sencha touch2?



Tejendra
30 Apr 2012, 1:09 AM
I have created "Hello World" webservice, I am trying to access webservice using Sencha touch2 and SDK. but it didn't show any output as well as error. I have used below code in App.js file.

Ext.Ajax.request({
url: 'http://localhost:3661/Service1.asmx?op=HelloWorld',
success: function(response) {
console.log("Success" + msg)
},
failure: function (msg) {
console.log("Failure" + msg)
}
});

when I tried to browse index.html page it didn't show me the output. can someone please guide me?

mitchellsimoens
2 May 2012, 5:38 AM
Any errors like cross-origin blocking?

Tejendra
2 May 2012, 10:14 PM
Hi,

Thanks for looking into this. No Error like cross-origin blocking. I have writen new code to call WCF service in app.js file as below :

Ext.Ajax.request({
url: 'http://localhost:2908/Service1.svc/',
method: 'get',
params: {value: 10},
callback: function(response, opts) {
console.log(response.responseText);
},
jsonData: { "Alert": {} },
headers: { 'Content-Type text/xml': 'application/json;charset=utf-8' },
success: function (response, opts) {
alert(response.responseText);
alert("Hi")
}
})


Now when I ran index.html file in crome browser it call's the service but does not return any output. when I press F12 it shows me below error :

" XMLHttpRequest cannot load http://localhost:2908/Service1.svc/?_dc=1336024918856&value=10. Origin http://localhost is not allowed by Access-Control-Allow-Origin.
app.js:6undefined"

Is it beacause of I am using ajax request to call WCF service? Do I need to use JSONP ?
I have tried to call wcf service using Jquery but looks like syntaxes of jquery not supported in app.js file.. can you please guide me?
Thanks,
Tejendra

mitchellsimoens
3 May 2012, 4:00 AM
So you are getting a cross-origin block error. YOu need to do one of two things, enable CORS on the server or use JsonP