PDA

View Full Version : JSON/web service - problem loading datastore



zlarson
5 Oct 2007, 7:36 AM
I have looked all through these forums for the past two days and tried applying everything i found with no luck so i thought i would post my situation:

This is my javascript that calls my web service:
(I have tempData and the use of a memoryProxy just to prove my problem is with the HttpProxy, it works fine when i use the MemoryProxy. When i use the HttpProxy the loadexception event is fired.)


var dropdownRecord = new Ext.data.Record.create([
{name:'id'},
{name:'text'}
]);

//tempData is used to show that a memoryProxy will work
var tempData = {'results':2, 'rows':[{'id':1, 'text':'New'},{'id':2, 'text':'In Progress'}]};

/* datastore for dropdown */
var dsDropDown = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url:'Services/WebService.asmx/GetDropDown'}),
//proxy: new Ext.data.MemoryProxy(tempData),
reader: new Ext.data.JsonReader({totalProperty:'results', root:'rows', id:'id'}, dropdownRecord)
});
dsDropDown.on('beforeload', function() {
dsDropDown.baseParams = {type:'STAT'};
});
dsDropDown.on('loadexception', function(){
alert('exception!');
});
dsDropDown.on('load', function(){
alert('loaded');
});
dsDropDown.load();
This is my web service setup:


using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml;
using System.Web.Script.Services;

namespace CurrentContents
{
[WebService(Namespace = "http://microsoft.com/webservices/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class WebService : System.Web.Services.WebService
{
private CurrentContents.DbWorker worker = null;
public WebService()
{
worker = new DbWorker();
}

[WebMethod(Description = "returns a JSON string of dropdown items")]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string GetDropDown( string type )
{
//return worker.GetDropdown(type);
return "{'results':7, 'rows': [{'id':1, 'text':'New'},{'id':2, 'text':'In Progress'}]}";
}

............

When i go to my wsdl and invoke this method i see:
(I would expect to be seeing just a string and not my string wrapped in xml?)


<?xml version="1.0" encoding="utf-8" ?>
<string xmlns="http://microsoft.com/webservices/">{'results':2, 'rows': [{'id':1, 'text':'New'},{'id':2, 'text':'In Progress'}]}</string>


What am i doing wrong?

Thanks.

evant
5 Oct 2007, 3:56 PM
You might want to check this out: http://jayrock.berlios.de/

Zheng
28 Oct 2007, 11:02 PM
Is there anything method for user to unwrap the json data without "<xml>" by ext?
thanks

JeffHowden
28 Oct 2007, 11:44 PM
No, you will find either xml or json, but not a mixture of both. Rather than forcing the client-side to adjust to what the server responds with, I' massage the server-side to return just json or just xml.

Zheng
29 Oct 2007, 7:57 PM
I use WebService to get data from database.
When the Jsondata come from server to client,it will be wrapped by xml

Json from server through webservice:


<?xml version="1.0" encoding="utf-8" ?>
<string xmlns="http://localhost:2308/PrayaOA/atdmng">{"Egression":[{"DEPARTMENT_NAME":"dept1","EMPLOYEE_NAME":"Tom","REASON":"reason","APPROVE_FLAG":"0","NO":"1"]}</string>


It cannot be read by JsonReader.

By the way , if I use the xml-format data,the "<" and ">" between "<string>" will be convert to "&lt:" and "&gt:".


<?xml version="1.0" encoding="utf-8" ?>
<string>
&lt;ApproveStatusDataSet&gt;
&lt;Egression&gt;
&lt;DEPARTMENT_NAME&gt;dept10&lt;/DEPARTMENT_NAME&gt;
&lt;EMPLOYEE_NAME&gt;Tom&lt;/EMPLOYEE_NAME&gt;
&lt;REASON&gt;reason&lt;/REASON&gt;
&lt;APPROVE_FLAG&gt;0&lt;/APPROVE_FLAG&gt;
&lt;NO&gt;1&lt;/NO&gt;
&lt;/Egression&gt;
&lt;/ApproveStatusDataSet&gt;
</string>


It also cannot be read by XmlReader.

Can I do something before the response.responseText is read?
Thanks