[web2py] Re: Consuming a web2py web service in C#?

2011-06-01 Thread Scott
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 codecsto 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 ima...@gmail.com 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


[web2py] Re: Consuming a web2py web service in C#?

2011-05-24 Thread ron_m
If you go to the web2py server admin app e.g. http://127.0.0.1:8000/admin 
and login you should see the name of the app containing the service and an 
errors link after the name. Click that and you will see the errors page and 
be able to see the stack trace.

When running as a Python process you can put print statements in your 
controller to get an idea of what the parameters look like coming into the 
request. The output should go out on the terminal you ran python web2py.py 
from. Be sure to comment out the print statements before embedding in a web 
server such as apache with WSGI or you will get tickets from the print 
statement.


[web2py] Re: Consuming a web2py web service in C#?

2011-05-23 Thread Matt
I wish I was at the point of resolving encoding issues.  Right now
every time I call the service, the only thing I get in the response is
the web2py Ticket Issued html page returned as a string.  Any
suggestions?

On May 22, 9:42 am, nick name i.like.privacy@gmail.com wrote:
 I am doing something similar, but using the .NET built in JSON DataContract
 serializer. The things I've hit so far:

 a) Anything other than a 200 return will raise an exception
 (understandable), but not give you access to the returned json (bad; e.g.
 403 responses often have useful data with them)
 b) dates, times, timespans use an MS extended encoding (\/Date(xxx)\/) that
 simplejson cannot generate on the server side (I've posted an ugly patch
 here on the list before)
 c) dictionaries have a super-weird encoding from the .NET side; I opted
 instead to send a list of keys and a list of values from the server.

 These may or may not be relevant to jayrock.


[web2py] Re: Consuming a web2py web service in C#?

2011-05-23 Thread pbreit
Can you post the error messages?

[web2py] Re: Consuming a web2py web service in C#?

2011-05-22 Thread nick name
I am doing something similar, but using the .NET built in JSON DataContract 
serializer. The things I've hit so far:

a) Anything other than a 200 return will raise an exception 
(understandable), but not give you access to the returned json (bad; e.g. 
403 responses often have useful data with them)
b) dates, times, timespans use an MS extended encoding (\/Date(xxx)\/) that 
simplejson cannot generate on the server side (I've posted an ugly patch 
here on the list before)
c) dictionaries have a super-weird encoding from the .NET side; I opted 
instead to send a list of keys and a list of values from the server.

These may or may not be relevant to jayrock.