[Soap-Python] [tornado] python webservice from SOAPpy import SOAPProxy

Rodrigo Ancavil rancavil at gmail.com
Fri Dec 2 16:51:57 CET 2011


Hi, Jia...

I seen the code of tornadows to find what is the situation...well, the API
is strict with the compliance of xml schema defined into the wsdl.

The web service waits the compliance of the xml schema of the wsdl. In this
case when you make:

print server.sum(200,10)

The xml message generated is:

<sum>
<v1>200</v1>
<v2>10</v2>
</sum>

And the v1 and v2 elements are not understand by the api, because this api
waits for the a and b elements, then is triggered the exception (at level
of the API).

I will checked the code of soaphandler.py of api tornadows.

Thanks....

Rodrigo.





2011/12/1 贾晓磊 <jiaxiaolei19871112 at gmail.com>

> Thanks for the insight. the problem is solved. the code below can work
> well.
>
>
> def test_tornadows_sum2():
>     """test for tornadows
>     """
>      url = "http://localhost:8000/SumService"
>     server = SOAPProxy(url, noroot=1)
>     server.config.debug=1
>     server.config.typed=0
>     print server.sum(a=200,b=10)
>
>
> #NOTE: do you find a funny phenomenon?
>
> if local programming, we can define a function "def test(a=1,b=2):  return
> a+b" can invoke it using "test(200,10)" successfully.
>
> while, in "SOAPProxy", we must write code as "print
> server.sum(a=200,b=10)".
> when use "print server.sum(200,10)", it returns an exception.
>
> #detail information:
>
> # server end:
>
>     def sum(self, a, b):
>         print 'a', a
>         print 'b', b
>         result = a + b
>         print 'result',
>
> client end:
>
> part 1:
> print server.sum(200,10)
>
> failed:
>
> *** Outgoing HTTP headers **********************************************
> POST /SumService HTTP/1.0
> Host: localhost:8000
> User-agent: SOAPpy 0.12.0 (http://pywebsvcs.sf.net)
> Content-type: text/xml; charset="UTF-8"
> Content-length: 282
> SOAPAction: "sum"
> ************************************************************************
> *** Outgoing SOAP ******************************************************
> <?xml version="1.0" encoding="UTF-8"?>
> <SOAP-ENV:Envelope
>   SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
>   xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
> >
> <SOAP-ENV:Body>
> <sum>
> <v1>200</v1>
> <v2>10</v2>
> </sum>
> </SOAP-ENV:Body>
> </SOAP-ENV:Envelope>
> ************************************************************************
> code= 200
> msg= OK
> headers= Content-Length: 516
> Content-Type: text/xml
> Server: TornadoServer/2.1.1
>
> content-type= text/xml
> data= <?xml version="1.0" ?><soapenv:Envelope
>
> xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
>
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>
> xsi:schemaLocation="http://schemas.xmlsoap.org/soap/envelope/
>
> http://schemas.xmlsoap.org/soap/envelope/
> "><soapenv:Header/><soapenv:Body><soapenv:Fault
>
> xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope">
> <faultcode/>
> <faultstring>Error in web service : sum() takes exactly 3 arguments (1
> given)</faultstring>
> </soapenv:Fault></soapenv:Body></soapenv:Envelope>
> *** Incoming HTTP headers **********************************************
> HTTP/1.? 200 OK
> Content-Length: 516
> Content-Type: text/xml
> Server: TornadoServer/2.1.1
> ************************************************************************
> *** Incoming SOAP ******************************************************
> <?xml version="1.0" ?><soapenv:Envelope
>
> xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
>
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>
> xsi:schemaLocation="http://schemas.xmlsoap.org/soap/envelope/
>
> http://schemas.xmlsoap.org/soap/envelope/
> "><soapenv:Header/><soapenv:Body><soapenv:Fault
>
> xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope">
> <faultcode/>
> <faultstring>Error in web service : sum() takes exactly 3 arguments (1
> given)</faultstring>
> </soapenv:Fault></soapenv:Body></soapenv:Envelope>
> ************************************************************************
> <SOAPpy.Types.structType Fault at 144746668>: {'faultcode': '',
> 'faultstring': 'Error in web
>
> service : sum() takes exactly 3 arguments (1 given)'}
>
>
> part 2:
>
> print server.sum(a=200,b=10)
>
> okay:
>
> *** Outgoing HTTP headers **********************************************
> POST /SumService HTTP/1.0
> Host: localhost:8000
> User-agent: SOAPpy 0.12.0 (http://pywebsvcs.sf.net)
> Content-type: text/xml; charset="UTF-8"
> Content-length: 278
> SOAPAction: "sum"
> ************************************************************************
> *** Outgoing SOAP ******************************************************
> <?xml version="1.0" encoding="UTF-8"?>
> <SOAP-ENV:Envelope
>   SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
>   xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
> >
> <SOAP-ENV:Body>
> <sum>
> <a>200</a>
> <b>10</b>
> </sum>
> </SOAP-ENV:Body>
> </SOAP-ENV:Envelope>
> ************************************************************************
> code= 200
> msg= OK
> headers= Content-Length: 344
> Content-Type: text/xml
> Server: TornadoServer/2.1.1
> Set-Cookie: _xsrf=bd30bb2d55624f8e99409b061fe4bb74; Path=/
>
> content-type= text/xml
> data= <?xml version="1.0" ?><soapenv:Envelope
>
> xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
>
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>
> xsi:schemaLocation="http://schemas.xmlsoap.org/soap/envelope/
>
> http://schemas.xmlsoap.org/soap/envelope/
> "><soapenv:Header/><soapenv:Body><returns>210</returns>
>
> </soapenv:Body></soapenv:Envelope>
> *** Incoming HTTP headers **********************************************
> HTTP/1.? 200 OK
> Content-Length: 344
> Content-Type: text/xml
> Server: TornadoServer/2.1.1
> Set-Cookie: _xsrf=bd30bb2d55624f8e99409b061fe4bb74; Path=/
> ************************************************************************
> *** Incoming SOAP ******************************************************
> <?xml version="1.0" ?><soapenv:Envelope
>
> xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
>
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>
> xsi:schemaLocation="http://schemas.xmlsoap.org/soap/envelope/
>
> http://schemas.xmlsoap.org/soap/envelope/
> "><soapenv:Header/><soapenv:Body><returns>210</returns>
>
> </soapenv:Body></soapenv:Envelope>
> ************************************************************************
> 210
>
> if idle, hope to get a response. Thanks again for the help.
>
> -- Jia Xiaolei
>
>
>
> On Fri, Dec 2, 2011 at 4:45 AM, Rodrigo Ancavil <rancavil at gmail.com>wrote:
>
>> Hi Jia.
>>
>> SOAPpy generates default XML SOAP messaging a bit confusing for web
>> services.
>>
>> If you set server.config.debug = 1, you can see the messages generated by
>> default.
>>
>> Below I send you a code that worked for me.
>>
>>
>> Here the code:
>> ===========
>>
>> from SOAPpy import SOAPProxy
>>
>> def test_tornadows_sum():
>>     """test for tornadows
>>     """
>>     #TODO:in this way, invoking tornadows is also failed, what a pity.
>>     url = "http://localhost:8000/SumService"
>>
>>     # noroot = 0 generate <sum SOAP-ENC:root="1">
>>     # noroot = 1 ommit SOAP-ENC:root="1", <sum>
>>
>>     server = SOAPProxy(url,noroot=1)
>>     # With debug = 1 show the communication and messages soap xml.
>>     server.config.debug = 1
>>
>>     # typed = 0 generates the types into the elements
>>     # <a xsi:type="xsd:int">2</a>
>>     # <b xsi:type="xsd:int">1</b>
>>     # with typed = 1 omits the types into the elements
>>     # <a>2</a>
>>     # <a>1</b>
>>     server.config.typed = 0
>>
>>     print
>>     # sending the parameters a=val1, b=val2, make that respect the
>> elements
>>     # defined in the schema of the wsdl.
>>     print "Result is : "+server.sum(a=200,b=10)
>>
>> test_tornadows_sum()
>>
>> I hope help you.
>>
>> Rodrigo.
>>
>>
>>
>>
>>
>> 2011/12/1 贾晓磊 <jiaxiaolei19871112 at gmail.com>
>>
>>> Hi, all:
>>>
>>> Is someone familiar to SOAPpy?
>>>
>>> First of all, I will admire I'm a newbie to soap, and SOAPpy can run
>>> successfully in some occasions.
>>>
>>> Now, my problem is:
>>>
>>> # server_sum.py
>>> 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 SumService(soaphandler.SoapHandler):
>>>
>>> @webservice(_params=[xmltypes.Integer,xmltypes.Integer],_returns=xmltypes.Integer)
>>>     def sum(self, a=1, b=1):
>>>         result = a + b
>>>         return result
>>>
>>> if __name__ == '__main__':
>>>     service = [('SumService',SumService)]
>>>     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()
>>>
>>> # sum_client.py
>>>
>>> from SOAPpy import SOAPProxy
>>>
>>> def test_tornadows_sum():
>>>     """test for tornadows
>>>     """
>>>     #TODO:in this way, invoking tornadows is also failed, what a pity.
>>>     url = "http://localhost:8000/SumService"
>>>     server = SOAPProxy(url)
>>>     print dir(server)
>>>     a = 22
>>>     b = 44
>>>     print server.sum(a,b)
>>>
>>>
>>> ------
>>> The server is okay.when I invoke the method in this way, it return the
>>> sum of 10 and 2.:
>>> import suds
>>> def test_tornadows_sum():
>>>     # it's okay, while the server provide a method.
>>>     url = "http://localhost:8000/SumService?wsdl"
>>>     client = suds.client.Client(url)
>>>     print 'client', client
>>>     a = 10
>>>     b = 2
>>>     output = client.service.sum(a,b)
>>>
>>> While, when i use SOAPProxy (sum_client.py), it failed. the errror
>>> message is :
>>>
>>> ['_SOAPProxy__Method', '_SOAPProxy__call', '__doc__', '__getattr__',
>>> '__init__', '__module__', '_callWithBody', 'config', 'encoding', 'header',
>>> 'http_proxy', 'invoke', 'methodattrs', 'namespace', 'noroot', 'proxy',
>>> 'simplify_objects', 'soapaction', 'throw_faults', 'transport',
>>> 'unwrap_results']
>>> <SOAPpy.Types.structType Fault at 141277356>: {'faultcode': '',
>>> 'faultstring': 'Error in web service : unbound prefix: line 1, column 0'}
>>>
>>> What should I do next ?
>>>
>>> #NOTE: the wsdl for the server is:
>>> http://172.16.2.46:8000/SumService?wsdl    # url is in my personal
>>> computer, you can read the wsdl below.
>>> <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
>>> xmlns:tns="http://127.0.1.1:8000/SumService/sum" xmlns:wsdl="
>>> http://schemas.xmlsoap.org/wsdl/"xmlns:xsd="
>>> http://www.w3.org/2001/XMLSchema" xmlns:xsi="
>>> http://www.w3.org/2001/XMLSchema-instance" name="SumService"
>>> targetNamespace="http://127.0.1.1:8000/SumService/sum">
>>> <wsdl:types>
>>> <xsd:schema targetNamespace="http://127.0.1.1:8000/SumService/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="SumServiceRequest">
>>> <wsdl:part element="tns:params" name="parameters"/>
>>> </wsdl:message>
>>> <wsdl:message name="SumServiceResponse">
>>> <wsdl:part element="tns:returns" name="parameters"/>
>>> </wsdl:message>
>>> <wsdl:portType name="SumServicePortType">
>>> <wsdl:operation name="sum">
>>> <wsdl:input message="tns:SumServiceRequest"/>
>>> <wsdl:output message="tns:SumServiceResponse"/>
>>> </wsdl:operation>
>>> </wsdl:portType>
>>> <wsdl:binding name="SumServiceBinding" type="tns:SumServicePortType">
>>> <soap:binding style="document" transport="
>>> http://schemas.xmlsoap.org/soap/http"/>
>>> <wsdl:operation name="sum">
>>> <soap:operation soapAction="http://127.0.1.1:8000/SumService" 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="SumService">
>>> <wsdl:port binding="tns:SumServiceBinding" name="SumServicePort">
>>> <soap:address location="http://127.0.1.1:8000/SumService"/>
>>> </wsdl:port>
>>> </wsdl:service>
>>> </wsdl:definitions>
>>>
>>> Any help will be highly appreciated. Thanks for your time and
>>> concentration again!
>>>
>>> -- Jia Xiaolei
>>>
>>>
>>
>
>
> --
> NAME: 贾晓磊/Jia Xiaolei
> MOBILE: 13011292217
> QQ: 281304051
> MICRO-BLOG:  http://weibo.com/2183890715
> GMAIL: jiaxiaolei19871112 at gmail.com <gmail%3Ajiaxiaolei19871112 at gmail.com>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/soap/attachments/20111202/43633157/attachment-0001.html>


More information about the Soap mailing list