a question about python webservice using tornado web service

452 views
Skip to first unread message

贾晓磊

unread,
Dec 5, 2011, 6:26:50 AM12/5/11
to python-...@googlegroups.com
Hi, all:

Recently I am doing something about webservice. In java, I developed a whole webservice which has a Axis2 server and a Axis2 client.
In python, the server end is tornadows, and the client is suds. In the inner of each language, it all works perfect, in other words, python suds invokes tornadows successfully and Axis2 client invokes Axis2 server well.

Now, come to the problems encountered with about tornadows:

1:First, i failed to invoke Axis2 server using python suds. then after some modifies in client, it's okay now . It tell me Axis2 is stable and strong and it should be trusted.

2:  In tornadows, I find that 

problem 1: it's  failed to define a method has no input parameters.


# server end:
# -*- coding:utf-8 -8-

import logging

import tornado.httpserver
import tornado.ioloop
import tornado.web
from tornadows import soaphandler
from tornadows import webservices
from tornadows import xmltypes
from tornadows.soaphandler import webservice
from tornado.options import define, options

define('mode', default='deploy')
define('port', type=int, default=8000)
options['logging'].set('warning')


class SMSService(soaphandler.SoapHandler):

    @webservice(_params=None,_returns=xmltypes.Integer)
    def getPrice(self,a):
        return 1987

if __name__ == '__main__':
    service = [('SMSService',SMSService)]
    app = webservices.WebService(service)
    ws  = tornado.httpserver.HTTPServer(app)

    ws.listen(options.port)
    logging.warn("SumService running on: localhost:%d", options.port)
    tornado.ioloop.IOLoop.instance().start()

when  in web browser,  type the url "http://[my own ip]:8000/SMSService?wsdl", the server is error.
# output:

WARNING:root:SMSService running on: localhost:8000
ERROR:root:Uncaught exception GET /SMSService?wsdl (172.16.2.65)
HTTPRequest(protocol='http', host='172.16.2.46:8000', method='GET', uri='/SMSService?wsdl', version='HTTP/1.1', remote_ip='172.16.2.65', body='', headers={'Accept-Language': 'zh-CN,zh;q=0.8', 'Accept-Encoding': 'gzip,deflate,sdch', 'Host': '172.16.2.46:8000', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.215 Safari/535.1', 'Accept-Charset': 'GBK,utf-8;q=0.7,*;q=0.3', 'Connection': 'keep-alive', 'Cookie': '_xsrf=18e703520a2f411f9ccc3056cb1dea64'})
Traceback (most recent call last):
  File "/usr/local/lib/python2.6/dist-packages/tornado/web.py", line 954, in _execute
    getattr(self, self.request.method.lower())(*args, **kwargs)
  File "/usr/local/lib/python2.6/dist-packages/tornadows/soaphandler.py", line 131, in get
    self.finish(wsdlfile.createWsdl().toxml())
  File "/usr/local/lib/python2.6/dist-packages/tornadows/wsdl.py", line 50, in createWsdl
    types += self._createComplexTypes(self._elementNameInput, self._arguments, self._elementInput)
  File "/usr/local/lib/python2.6/dist-packages/tornadows/wsdl.py", line 140, in _createComplexTypes
    elif issubclass(elements[e],xmltypes.PrimitiveType):
TypeError: issubclass() arg 1 must be a class
ERROR:root:500 GET /SMSService?wsdl (172.16.2.65) 3.03ms
WARNING:root:404 GET /favicon.ico (172.16.2.65) 0.28ms

# the client output:
Traceback (most recent call last):
  File "suds_client.py", line 737, in <module>
    test_tornadows_getPrice()
  File "suds_client.py", line 114, in test_tornadows_getPrice
    client = suds.client.Client(url,cache=None,faults=False)
  File "/usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/client.py", line 109, in __init__
    self.wsdl = Definitions(url, options)
  File "/usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/wsdl.py", line 172, in __init__
    root = p.parse(url=url).root()
  File "/usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/sax/parser.py", line 133, in parse
    fp = self.transport.open(Request(url))
  File "/usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/transport/https.py", line 69, in open
    return  HttpTransport.open(self, request)
  File "/usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/transport/http.py", line 72, in open
    raise TransportError(str(e), e.code, e.fp)
suds.transport.TransportError: HTTP Error 500: Internal Server Error

#NOTE:  If we need a function has no input or no output,  how to write the code ??

problem 2:  it's failed to create two soap method in a class.When i make two methods in the class as flows: 

class SMSService(soaphandler.SoapHandler):
    @webservice(_params=xmltypes.String,_returns=xmltypes.Integer)
    def getPrice(self,a):
        return 1987

    @webservice(_params=[xmltypes.Integer,xmltypes.Integer],_returns=xmltypes.Integer)
    def sum(self, a=1, b=2):
        result = a + b
        return result

I get the wsdl is as follows(it has only one function: sum):
<wsdl:types>
<xsd:schema targetNamespace="http://127.0.1.1:8000/SMSService/sum">
<xsd:complexType name="paramsTypes">
<xsd:sequence>
<xsd:element name="a" type="xsd:integer"/>
<xsd:element name="b" type="xsd:integer"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="params" type="tns:paramsTypes"/>
<xsd:element name="returns" type="xsd:integer"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="SMSServiceRequest">
<wsdl:part element="tns:params" name="parameters"/>
</wsdl:message>
<wsdl:message name="SMSServiceResponse">
<wsdl:part element="tns:returns" name="parameters"/>
</wsdl:message>
<wsdl:portType name="SMSServicePortType">
<wsdl:operation name="sum">
<wsdl:input message="tns:SMSServiceRequest"/>
<wsdl:output message="tns:SMSServiceResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="SMSServiceBinding" type="tns:SMSServicePortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="sum">
<soap:operation soapAction="http://127.0.1.1:8000/SMSService" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="SMSService">
<wsdl:port binding="tns:SMSServiceBinding" name="SMSServicePort">
<soap:address location="http://127.0.1.1:8000/SMSService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

#NOTE: if we would like to define more than a method in a class, how should we do?

Thanks for your time and concentration.

-- Jia Xiaolei

Rodrigo Ancavil

unread,
Dec 5, 2011, 7:51:25 AM12/5/11
to python-...@googlegroups.com
Hi Jia...

Thank for the analysis and comments of tornadows, I will check and modify the code, based in their comments.

Again, Thank.

Rodrigo.

2011/12/5 贾晓磊 <jiaxiaole...@gmail.com>

贾晓磊

unread,
Dec 5, 2011, 7:59:51 AM12/5/11
to python-...@googlegroups.com
Hi, Rodrigo:

Thanks for your replay. 

These days, I have been doing something about webservice. I like and use tornado, certainly contains   tornadows and choice a good python server-end for web service is a bit important. 
Hope the problem be solved as soon as possible.
Hope tornado becomes more and more stable and strong.

-- Jia Xiaolei


--
NAME: 贾晓磊/Jia Xiaolei
MOBILE: 13011292217
QQ: 281304051

Reply all
Reply to author
Forward
0 new messages