On Wed, Aug 1, 2012 at 2:22 PM, Eric Paul <[email protected]> wrote:
> Derrell,****
>
> ** **
>
> Thanks for your help. You cleared up a couple of key points which got me
> moving in the right direction again.****
>
> I wanted to reply to this so my solution will be there for someone else in
> the future.****
>
> ** **
>
> I think it’s a bit deceiving on the part of qooxdoo to include a
> setCrossDomain(true) on the RPC class.****
>
> If you make that call with “setCrossDomain(true)” it becomes a whole new
> beast and is no longer a standard json-rpc request.
>
That's somewhat harsh. JSON-RPC is transport-agnostic. It is effectively a
protocol that describes how to encode a message, to be sent by some means
undefined by JSON-RPC, to a remote server which understands that protocol.
Until very recently, it was not even possible to send cross-domain requests
using XMLHttpRequest, so various other transports were implemented to allow
transporting JSON-RPC messages between client and server. Even today,
XMLHttpRequest can only be used for cross-domain requests if special
procedures are followed, and the server explicitly allows it.
The mechanism used by the Script transport in qooxdoo is effectively JSONP.
It happens to predate that term and definition, so the callback method is
hard-coded rather than being specifyable in the URL. There is a newer set
of classes -- qx.io.request.* -- that implement JSONP exactly to the
standard. I have less experience with those classes.
> ****
>
> My next struggle was in trying to implement one of the many Asp.Net
> methods for handling json (MVC 4 Web API, JayRock.Net, etc.).****
>
> None of the standard methods understand what qooxdoo sends. As far as I
> can tell qooxdoo has its own ideas about how to send a cross domain request.
>
Nope. If you implement something that responds to a JSONP request, and have
it default to the callback name that qooxdoo uses if a callback method name
is not provided, you'll be entirely standards compliant.
> ****
>
> I did try using the Jsonp class but I couldn’t figure out how to send data
> from qooxdoo. It has a couple of “parameter” methods but no “setData”
> method.
>
Right. That's the other (newer) set of classes I mentioned above. You *can*
do what you need with those -- there's some mechanism (apparently other
than setData, if that method isn't available) -- but it's entirely
different than what we've been discussing.
> I could however get MVC 4 Web API to respond to a qooxdoo Jsonp call. I
> used:****
>
> ** **
>
> var req = new qx.io.request.Jsonp();****
>
> req.setUrl("http://74.143.64.2:5040/jsonp.aspx");****
>
> ** **
>
> req.addListener("success", function(e) {****
>
> var req2 = e.getTarget();****
>
> ** **
>
> // HTTP status code indicating success, e.g. 200****
>
> console.log("Status:" + req2.getStatus());****
>
> ** **
>
> // "success"****
>
> console.log("Phase:" + req2.getPhase());****
>
> ** **
>
> // JSON response****
>
> console.log("response:" + req2.getResponse());****
>
> }, this);****
>
> ** **
>
> // Send request****
>
> req.send();****
>
> ** **
>
> and got:****
>
> ** **
>
> 10545124 qx.application.Standalone[521-0]: Starting application 'Custom
> Code (modified)' ...
> playground.js:203<http://demo.qooxdoo.org/current/playground/script/playground.js>
> ****
>
> 10545128 qx.application.Standalone[521-0]: Successfully started.
> playground.js:203<http://demo.qooxdoo.org/current/playground/script/playground.js>
> ****
>
> Status:200****
>
> Phase:success****
>
> response:[object Object]****
>
> ** **
>
> My .Net code was just a page with the following in the page_load:****
>
> ** **
>
> //JSNONP****
>
> string Callback = Request.QueryString["callback"];****
>
> if (!string.IsNullOrEmpty(Callback))****
>
> {****
>
> // *** Do whatever you need****
>
> Response.ContentType = "application/javascript";****
>
> Response.Write(Callback + "( {\"x\":10 , \"y\":100} );");****
>
> }****
>
> Response.End();****
>
> ** **
>
> ** **
>
> After realizing what the content return type needed to be and
> understanding the format of the data being sent I decided just to build my
> own service for qooxdoo to talk to. Here is my final solution:****
>
> ** **
>
> Qooxdoo code:****
>
> ** **
>
> var req = new qx.io.remote.Request("http://74.143.64.2:5040/JSONP.aspx");*
> ***
>
> req.setMethod("POST");****
>
> req.setData('{"Id":"10", "Data":"chaka"}');****
>
> req.setCrossDomain(true);****
>
> ****
>
> req.addListener("completed", function(e) {****
>
> alert(e.getContent());****
>
> ****
>
> }, this);****
>
> ****
>
> req.send();****
>
> ** **
>
> This generates a “GET” request to a plain old aspx page:
>
That actually sounds like a bug. You are specifying that the method is POST
but that it's cross-domain. There is no transport capable of issuing a POST
request for cross-domain. Instead, it just silently gave you a GET request
instead of a POST request, which I guess if fine for your purpose, but
isn't what should have happened. It should have told that there was no
transport available to meet the requirements that you specified.
> ****
>
> ** **
>
> Request URL:
> http://74.143.64.2:5040/JSONP.aspx?_ScriptTransport_id=29&nocache=1343843345160&_ScriptTransport_data=%7B%22Id%22%3A%2210%22%2C%20%22Data%22%3A%22chaka%22%7D
> ****
>
> Request Method:GET****
>
> Status Code:200 OK****
>
> ** **
>
> Then I have an aspx page with the following Page_load method:****
>
> ** **
>
> using System.Text;****
>
> using System.Web.Script.Serialization;****
>
> ** **
>
> protected void Page_Load(object sender, EventArgs e)****
>
> {****
>
> //Use the JS Serializer to convert to/from json format****
>
> JavaScriptSerializer converter = new JavaScriptSerializer();****
>
> ** **
>
> string Id = System.Web.HttpContext.Current.Request.QueryString[
> "_ScriptTransport_id"];****
>
> string data = System.Web.HttpContext.Current.Request.QueryString[
> "_ScriptTransport_data"];****
>
> ** **
>
> //Convert the data to the expected object****
>
> try****
>
> {****
>
> ReturnData receiveData = converter.Deserialize<ReturnData>(data);*
> ***
>
> ** **
>
> //do something with the data -- like write it to a file****
>
> StringBuilder sb = new StringBuilder();****
>
> sb.AppendLine(String.Format("Id: {0}", receiveData.Id));****
>
> sb.AppendLine(String.Format("Data: {0}", receiveData.Data));****
>
> ** **
>
> string file = System.Web.HttpContext.Current.Server.MapPath(
> "~/Files") + "\\test.txt";****
>
> System.IO.File.WriteAllText(file, sb.ToString());****
>
> ** **
>
> }****
>
> catch (Exception)****
>
> {****
>
> //if the serialzation failes throw an error****
>
> throw new Exception("Error: Bad JSON Data sent, unable to
> deserialize");****
>
> }****
>
> ** **
>
> //Create an object as return data****
>
> ReturnData d = new ReturnData();****
>
> d.Id = 5;****
>
> d.Data = "test";****
>
> ** **
>
> //convert the objet into json format****
>
> string serializedString = converter.Serialize(d);****
>
> ** **
>
> //return the response as something qooxdoo understands (transmits a
> json object)****
>
> Response.ContentType = "application/javascript";****
>
>
> Response.Write(String.Format("qx.io.remote.transport.Script._requestFinished({0},
> {1});", Id, serializedString));****
>
> Response.End();****
>
> }****
>
> ** **
>
> All-in-all a relatively simple solution—once I clearly understood the
> problem. ****
>
> It does raise another question. I wonder if there is a limit on the amount
> of data that can be sent using this method?
>
There is a limit on the amount of data you can send *to* the server,
because it must be encoded in the URL of a GET request. The response is not
size-limited, AFAIK.
Cheers,
Derrell
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel