This is what I have concluded...

The problem is that many "Windows" based JSON-RPC serializers
(Including jayrock) and proxy's append a 3 byte UTF-8 BOM (Byte Order
Mark) to the beginning of the resulting encoded JSON text that is sent
in the body of the HTML request. Note that this is not a "feature"
added by jayrock or any other JSON-RPC library, it is a Windows OS
specific encoding practice for UTF-8 strings. Python does not bother
with this because UTF-8 is it's natural language encoding and assumes
this without being told by use of the BOM.

So, what should be sent as '{"params":"hello","id":
1,"method":"echo"}'  for example is sent as '\xef\xbb
\xbf{"params":"hello","id":1,"method":"echo"}' by jayrock.
Neither simplejson or web2py's serve_jsonrpc function (in tools.py)
check for this UTF-8 BOM when decoding the JSON string.

I am not 100% sure where this problem should be fixed in the code, in
simplejson's decode function or web2py's serve_jsonrpc function, but I
made these changes to the code in web2py's serve_jsonrpc function:

From:
----------------------------------
request = self.environment['request']
methods = self.jsonrpc_procedures
data =
simplejson.loads(request.body.read())
id, method, params = data['id'], data['method'], data.get('params','')

To:  (added: import codecs    to the top of the file)
----------------------------------
request = self.environment['request']
methods = self.jsonrpc_procedures
#
added
theBody = request.body.read()
if theBody.startswith( codecs.BOM_UTF8 ):
        theBody = theBody[3:]
#data =
simplejson.loads(request.body.read())
data = simplejson.loads(theBody)
id, method, params = data['id'], data['method'], data.get('params','')


This strips out the 3 byte UTF-8 BOM at the beginning of the body of
the HTML and calls from jayrock's JSON-RPC client's work just fine.


This is something that needs to be fixed and included in web2py's
source. Or perhaps the fix belongs in the simplejson library?



On May 20, 4:23 pm, Matt <[email protected]> wrote:
> Anyone using web2py as the web service and then consuming the service
> via json-rpc in C#? I imagine this is possible, but seem to have quite
> some time trying to get this to work.
>
> I'm usingjayrockas my json-rpc C# parser and setting the url to the
> service to be my exposed web2py service but can't seem to get the
> data.
>
> I'd be interested to know if anyone is doing something similar.
>
> Thanks.
> -m

Reply via email to