PDA

View Full Version : JayRock-RPC woes



zlarson
11 Oct 2007, 8:32 AM
I went down the JayRock road...

Background: I want to setup a datastore of values for a dropdown. I want to pass the dropdown type of 'STAT' in the baseParams config option for the datastore. When I try debugging this with VS I get this:

Microsoft JScript runtime error: 'result.rows' is null or not an object

on the return line of this:


function anonymous(obj) {
return obj.result.rows
}


The stack trace in the error:


" at Jayrock.Json.Conversion.Converters.ImporterBase.ThrowNotSupported(JsonTokenClass clazz) in c:\Projects\Public\Jayrock\rel\rel-0.9.8316\src\Jayrock.Json\Json\Conversion\Converters\ImporterBase.cs:line 118
at Jayrock.Json.Conversion.Converters.ImporterBase.ImportFromObject(ImportContext context, JsonReader reader) in c:\Projects\Public\Jayrock\rel\rel-0.9.8316\src\Jayrock.Json\Json\Conversion\Converters\ImporterBase.cs:line 101
at Jayrock.Json.Conversion.Converters.ImporterBase.Import(ImportContext context, JsonReader reader) in c:\Projects\Public\Jayrock\rel\rel-0.9.8316\src\Jayrock.Json\Json\Conversion\Converters\ImporterBase.cs:line 83
at Jayrock.Json.Conversion.ImportContext.Import(Type type, JsonReader reader) in c:\Projects\Public\Jayrock\rel\rel-0.9.8316\src\Jayrock.Json\Json\Conversion\ImportContext.cs:line 63
at Jayrock.JsonRpc.JsonRpcDispatcher.ReadParameters(Method method, JsonReader reader, ImportContext importContext) in c:\Projects\Public\Jayrock\rel\rel-0.9.8316\src\Jayrock\JsonRpc\JsonRpcDispatcher.cs:line 388
at Jayrock.JsonRpc.JsonRpcDispatcher.ParseRequest(TextReader input) in c:\Projects\Public\Jayrock\rel\rel-0.9.8316\src\Jayrock\JsonRpc\JsonRpcDispatcher.cs:line 317
at Jayrock.JsonRpc.JsonRpcDispatcher.Process(TextReader input, TextWriter output) in c:\Projects\Public\Jayrock\rel\rel-0.9.8316\src\Jayrock\JsonRpc\JsonRpcDispatcher.cs:line 127"


I have come to the conclusion that I am not passing the parameters correctly. What am I doing wrong???


proxy methods:


var rpcProxy = function(rpc, listMethod)
{
rpcProxy.superclass.constructor.call(this);
this.load = function(params, reader, callback, scope, arg)
{
rpc[listMethod](params, this.loadResponse.createDelegate(this, [reader, callback, scope, arg], true)).call(ext_channel);
}

this.loadResponse = function(response, reader, callback, scope, arg)
{
var result;
result = reader.read(response);
callback.call(scope||this, result, arg, true) ;
}
};
var ext_channel = function(call)
{
alert(Ext.encode(call.request));
if (typeof(call.callback) !== 'function')
thrownew Error("The EXT channel does not support synchronous methods.");

call.yuiconn = Ext.Ajax.request ({
url: call.url,
params: {"JSON-RPC": Ext.encode(call.request)},
success: function(response, options) {
call.callback(response);
},
failure: function(response, options) {
call.callback({xhr:response});
}
});
return call;
};

Ext.extend(rpcProxy, Ext.data.DataProxy, {}) ;


myobjecthandler.ashx


<%@WebHandlerLanguage="C#"Class="myobjecthandler" %>

[JsonRpcService("myObject")]
public class myobjecthandler : CurrentContents.HandlerBase
{}


HandlerBase.cs


namespace CurrentContents
{
///<summary>
/// Summary description for HandlerBase
///</summary>
public classHandlerBase : JsonRpcHandler
{
private CurrentContents.DbWorker worker = null;
public HandlerBase()
{}
[JsonRpcMethod("getDropDown", Idempotent = true)]
public virtual DataTable GetDropDown(string args)
{
worker = newDbWorker();
return worker.GetDropdown("STAT"); //STAT is being passed just to force a positive return
}
}
}


setup my datastore:


var dd_rec = new Ext.data.Record.create([{name:'item_id', mapping:0}, {name:'item_text', mapping:1}]);
var dd_ds = new Ext.data.Store({
proxy: new rpcProxy(myObject.rpc, "getDropDown"),
reader: new Ext.data.JsonReader({root:'result.rows', id:'item_id'}, dd_rec),
remoteSort: false,
baseParams: {arg1:'STAT', arg2:'TEST'}
}
);
dd_ds.load();