michelk
21 Sep 2010, 12:46 PM
Hi,
After several hours spitting though the examples and forums I can’t get it to work. This should be so simple ….
I have created a C# dotnet 3.5 webservice what is returning json data.
I have created a sencha touch application that calls the webservice and gets the json results and put this in a store.
The webservice is working okay. Because when I do a Ext.Ajax.request and look at the responsetext I see the json data.
But when I do the same in the a Ext.data.Store with a ajax proxy , the store.getcount() is always 0.
The strange part is when I replace the webservice url to load directly a natve .json file that also on the iis site the data is loaded.
So I think IIS 7 is doing something with the json webservice output. ??? (and yes , I have set the root to ‘d’)
And when using the ajax proxy , how can I get the http responsetext to see if the http call was successful ? Since I can’t use the success and failure events as I can with the ext.ajax.request ??
See the code below. I think I’m not alone here and a good example will help a lot of sencha touch newbie’s ;-))
Thanks All for your time
Michel
Ext.setup({
fullscreen: true,
glossOnIcon: false,
onReady: function () {
// to test the call
Ext.Ajax.request({
url: './../scom_ipad/service1.asmx/GetAllAlerts',
method: 'GET',
jsonData: { "Alert": {} },
headers: { 'Content-Type': 'application/json;charset=utf-8' },
success: function (response, opts) {
alert(response.responseText);
},
failure: function (response, opts) {
alert(response.responseText);
}
})
// to load the store
var model = Ext.regModel('model', {
fields: [{ name: '__type', type: 'string' }, //added this because the responsetext was show this as “__type”:”Webservice1.Alert”. Is this needed???
{ name: 'Name', type: 'string' },
{ name: 'Description', type: 'string' },
{ name: 'ID', type: 'float' }
]
});
// load it
var store = new Ext.data.Store({
model: 'model',
autoLoad: true,
proxy: {
type: 'ajax',
url: './../scom_ipad/service1.asmx/GetAllAlerts',
// Ask for Json response
headers: { 'Content-Type': 'application/json;charset=utf-8' },
method: 'GET',
reader: {
type: 'json',
root: 'd'
}
}
});
// display the row count , but it is Always 0
alert('count ' + store.getCount());
var tpl = new Ext.XTemplate(
'<tpl for=".">',
'<div class="thumb-wrap" id="{ID}">',
'<div class="thumb"><img src="{Description}" title="{Name}"></div>',
'<span class="x-editable">{Name}</span></div>',
'</tpl>',
'<div class="x-clear"></div>'
);
// show the store row on the screen but nothing is shown.
var panel = new Ext.Panel({
id: 'images-view',
fullscreen: true,
dockedItems: [ // Added for effect
{
dock: 'top',
xtype: 'toolbar',
items: [{
text: 'btn top'
}]
},
{
dock: 'bottom',
xtype: 'toolbar',
items: [{
text: 'btn bottom'
}]
}
],
items: [new Ext.DataView({
store: store,
tpl: tpl,
autoHeight: true,
multiSelect: true,
overClass: 'x-view-over',
itemSelector: 'div.thumb-wrap',
emptyText: 'No images to display'
})]
});
}
});
-----------------------------------------------
---c# Webservice
-----------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Xml;
using System.Web.Script.Serialization;
using System.Web.Script.Services;
namespace WebService1
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json,UseHttpGet = true, XmlSerializeString = false)]
public Alert[] GetAlerts()
{
Alert[] p = new Alert[2];
p[0] = new Alert (1,"1aadd", "ddd");
p[1] = new Alert(2,"2aadd", "aaaa");
return (p);
}
}
public class Alert
{
public string Name { get; set; }
public string Description { get; set; }
public int ID { get; set; }
public Alert() { }
public Alert(int Key,string firstname, string lastname)
{
ID = Key;
Name = firstname;
Description = lastname;
}
}
}
After several hours spitting though the examples and forums I can’t get it to work. This should be so simple ….
I have created a C# dotnet 3.5 webservice what is returning json data.
I have created a sencha touch application that calls the webservice and gets the json results and put this in a store.
The webservice is working okay. Because when I do a Ext.Ajax.request and look at the responsetext I see the json data.
But when I do the same in the a Ext.data.Store with a ajax proxy , the store.getcount() is always 0.
The strange part is when I replace the webservice url to load directly a natve .json file that also on the iis site the data is loaded.
So I think IIS 7 is doing something with the json webservice output. ??? (and yes , I have set the root to ‘d’)
And when using the ajax proxy , how can I get the http responsetext to see if the http call was successful ? Since I can’t use the success and failure events as I can with the ext.ajax.request ??
See the code below. I think I’m not alone here and a good example will help a lot of sencha touch newbie’s ;-))
Thanks All for your time
Michel
Ext.setup({
fullscreen: true,
glossOnIcon: false,
onReady: function () {
// to test the call
Ext.Ajax.request({
url: './../scom_ipad/service1.asmx/GetAllAlerts',
method: 'GET',
jsonData: { "Alert": {} },
headers: { 'Content-Type': 'application/json;charset=utf-8' },
success: function (response, opts) {
alert(response.responseText);
},
failure: function (response, opts) {
alert(response.responseText);
}
})
// to load the store
var model = Ext.regModel('model', {
fields: [{ name: '__type', type: 'string' }, //added this because the responsetext was show this as “__type”:”Webservice1.Alert”. Is this needed???
{ name: 'Name', type: 'string' },
{ name: 'Description', type: 'string' },
{ name: 'ID', type: 'float' }
]
});
// load it
var store = new Ext.data.Store({
model: 'model',
autoLoad: true,
proxy: {
type: 'ajax',
url: './../scom_ipad/service1.asmx/GetAllAlerts',
// Ask for Json response
headers: { 'Content-Type': 'application/json;charset=utf-8' },
method: 'GET',
reader: {
type: 'json',
root: 'd'
}
}
});
// display the row count , but it is Always 0
alert('count ' + store.getCount());
var tpl = new Ext.XTemplate(
'<tpl for=".">',
'<div class="thumb-wrap" id="{ID}">',
'<div class="thumb"><img src="{Description}" title="{Name}"></div>',
'<span class="x-editable">{Name}</span></div>',
'</tpl>',
'<div class="x-clear"></div>'
);
// show the store row on the screen but nothing is shown.
var panel = new Ext.Panel({
id: 'images-view',
fullscreen: true,
dockedItems: [ // Added for effect
{
dock: 'top',
xtype: 'toolbar',
items: [{
text: 'btn top'
}]
},
{
dock: 'bottom',
xtype: 'toolbar',
items: [{
text: 'btn bottom'
}]
}
],
items: [new Ext.DataView({
store: store,
tpl: tpl,
autoHeight: true,
multiSelect: true,
overClass: 'x-view-over',
itemSelector: 'div.thumb-wrap',
emptyText: 'No images to display'
})]
});
}
});
-----------------------------------------------
---c# Webservice
-----------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Xml;
using System.Web.Script.Serialization;
using System.Web.Script.Services;
namespace WebService1
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json,UseHttpGet = true, XmlSerializeString = false)]
public Alert[] GetAlerts()
{
Alert[] p = new Alert[2];
p[0] = new Alert (1,"1aadd", "ddd");
p[1] = new Alert(2,"2aadd", "aaaa");
return (p);
}
}
public class Alert
{
public string Name { get; set; }
public string Description { get; set; }
public int ID { get; set; }
public Alert() { }
public Alert(int Key,string firstname, string lastname)
{
ID = Key;
Name = firstname;
Description = lastname;
}
}
}