سؤال

I'm exploring jsonrpc 2 for a web service. I have some experience with java rmi and very much liked that. To make things easy I using the zend framework so I think I like to use that library. There is however one thing i am missing. how do I make a procedure send back a reference to an other object.

I get that is not within the protocol because its about procedures but it would still be a useful thing. Like with the java rmi I could pick objects to send by value (serialize) or reference (remote object proxy). So what is the best way do solve this? are there any standards for this that most library's use?

I spend a view hours on google looking for this and can think of a solution (like return a url) but, I would rather use a standard then design something new.

There is one other thing i would like your opinion on. I heard an architect rand about the protocol's feature of sending batches of call's. Are the considered nice or dirty? (he thinks they where ugly but i can think of use for then)

update

I think the nicesed way is just to return a remoteref object with a url to the object. That way its only a small wrappen and a litle documentation. Yet i would like to know if there is a commen way to do this.

SMD Posibilitie's

There might be some way to specify the return type in my smd, is there anyone with idears of how to give a reference to another page in my smd return type? Or does anyone know a good explenation for the zend_json_smd class?

هل كانت مفيدة؟

المحلول

You can't return a reference of any kind via JSON-RPC.

There is no standard to do so (afaik) because RPC is stateless, and most developers prefer it that way. This simplicity is what makes JSON-RPC so desirable to client-side developers over SOAP (and other messes).

You could however adopt a convention in your return values that some JSON constructs should be treated as "cues" to manufacture remote "object" proxies. For example, you could create a modified JSON de-serialiser that turns:

{
    "__remote_object": {
        "class":     "Some.Remote.Class",
        "remote_id": 54625143,
        "smd":       "http://domain/path/to/further.smd",
        "init_with": { ... Initial state of object ...  }
    }
}

Into a remote object proxy by:

  • creating a local object with a prototype named after class, initialised via init_with
  • downloading & processing the smd URL
  • creating a local proxy method (in the object proxy) for each procedure exposed via the API, such that they pass the remote_id to the server with each call (so that the server knows which remote object proxy maps to which server-side object.)

While this scheme would be workable, there are plenty of moving parts, and the code is much larger and more complicated on the client-side than for normal JSON-RPC.

JSON-RPC itself is not well standardised, so most extensions (even SMD) are merely conventions around method-names and payloads.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top