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 贾晓磊 <[email protected]>

> 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
>
>
_______________________________________________
Soap mailing list
[email protected]
http://mail.python.org/mailman/listinfo/soap

Reply via email to