[Soap-Python] some questions about soaplib

Burak Arslan burak.arslan at arskom.com.tr
Tue Dec 6 15:59:05 CET 2011


Hi Jia,

If you need a soap client, just use suds and don't bother with
rpclib/soaplib. It's just incomplete. Currently, the only advantage of
using rpclib as a soap client is its speed and if you need speed that
bad, you should not be using soap (or xml) anyway.

Does this answer your question, or is there any more questions hidden in
the heap below?

best,
burak

On 12/06/11 16:03, 贾晓磊 wrote:
> Hi, all:
>
> Recently, I have been do something about python webservice. Above all
> the methods of python webservice, soaplib is welcome and popular. When
> using soaplib, some problems puzzled me as follows.
>
> porlbem 1: soaplib provide client-side or not?
> Usually, I use soaplib as follows:
>
> # file-name: soaplib_server.py:
> # -*- coding:utf-8 -*-
>
> from soaplib.wsgi_soap import SimpleWSGISoapApp
> from soaplib.service import soapmethod
> from soaplib.serializers.clazz import ClassSerializer
> from soaplib.serializers.primitive import String, Integer, Array, DateTime
>
>
> class SMS(ClassSerializer):
>     class types:
>         mobile = String
>         content = String
>
> class SMSService(SimpleWSGISoapApp):
>     @soapmethod(String, _returns=Array(SMS))
>     def get_sms(self,id):
>         sms_lst = []
>         sms = SMS()
>         sms.mobile = "13011292217"
>         sms.content = "hi, it's a test!"
>         sms_lst.append(sms)
>         return sms_lst
>
> def make_client():
>     from soaplib.client import make_service_client
>     client = make_service_client('http://localhost:7789/' ,SMSService())
>     return client
>
> if __name__=='__main__':
>     try:
>         from wsgiref.simple_server import make_server
>         server = make_server('localhost', 7789,SMSService())
>         server.serve_forever()
>     except ImportError:
>         print "Error: example server code requires Python >= 2.5"
>
> #file-name: suds_client.py
> import suds
>
> def test_soaplib3():
> import logging
>     logging.basicConfig(level=logging.ERROR)
>
>     url = "http://localhost:7789/?wsdl"
>     client = suds.client.Client(url,cache=None)
>     print 'client', client
>     output = client.service.get_sms('jia')
>     print 'output', output
>
> #NOTE: Certainly, it's okay. Below is the output: 
>
> #output: 
> client
> Suds ( https://fedorahosted.org/suds/ )  version: 0.3.7 GA  build:
> R580-20091016
>
> Service ( SMSService ) tns="SMSService.SMSService"
>    Prefixes (1)
>       ns0 = "SMSService.SMSService"
>    Ports (1):
>       (SMSService)
>          Methods (1):
>             get_sms(xs:string id, )
>          Types (4):
>             SMS
>             SMSArray
>             get_sms
>             get_smsResponse
>
>
> output (SMSArray){
>    _type = "tns:SMSArray"
>    SMS[] =
>       (SMS){
>          content = "hi, it's a test!"
>          mobile = "13011292217"
>       },
>  }
>
> #NOTE: do you find the "def make_client():" in the server-side ? It's
> no use when we use suds_client.py.  Now, let me talk the problem: 
> I think soaplib is only a server-side and without client, you also can
> find the words as follows in "http://soaplib.github.com/soaplib/2_0/":
> "Soaplib is an easy to use Python library for publishing SOAP web
> services using WSDL 1.1 standard, and answering SOAP 1.1 requests.
> With a very small amount of code, soaplib allows you to write a useful
> web service and deploy it as a WSGI application. (Non-WSGI scenarios
> are also supported.)" 
> Most of scenes,  soaplib make as server and suds did for client. They
> can work together well.
> In a web page, I found someone use client by soaplib, the client can
> be write as follows:
>
> # file-name: soaplib_client.py
> # -*- coding:utf-8 -*-
>
> from soaplib_server3 import SMSService
> from soaplib_server3 import make_client
> import lxml.etree as et
>
> a = make_client()
> ret = a.get_sms('jia')
> print 'ret:', ret
> print 'type of ret:', type(ret)
> for i,r in enumerate(ret):
>     print 'i:',i, r.mobile, r.content
>
> #output:
> ret: [<soaplib_server3.SMS object at 0x8ecf7ec>]
> type of ret: <type 'list'>
> i: 0 13011292217 hi, it's a test!
>
> #NOTE: now, the questions are :
> 1: Whether soaplib can provide client? 
> 2: If the answer for question 1 is okay, then the second question is :
> how to provide a webservice client using soaplib? Is the method
> "client = make_service_client('http://localhost:7789/' ,SMSService())"
> which is be used in my soaplib_serve.py?
> 3: if you agree that soaplib can make as websevice client-side, I
> would like to ask: The client relays so heavily on sever-side, in the
> client-side, it requests some classes or modules in server side are
> imported. If we use soaplib-client to invoke a remote server(it may be
> developed in Java, C#, php or other language, or python which is not
> in the some local), how we get the class in server?
>
> I do not whether i speak my question clearly. In actual fact, what I
> eager to know is how to provide a client-side using soaplib if soaplib
> can.  
>
> part 2:  Is there someone find it spend much time and not stable to
> invoke soaplib using suds as follows.
> #NOTE: the code can also be found in
> "http://soaplib.github.com/soaplib/2_0/pages/helloworld.html"
> # soaplib_server.py
> import soaplib
> from soaplib.core.service import soap
> from soaplib.core.service import rpc, DefinitionBase
> from soaplib.core.model.primitive import String, Integer
> from soaplib.core.server import wsgi
> from soaplib.core.model.clazz import Array
> from soaplib.core import Application
> class HelloWorldService(DefinitionBase):
>
>     @soap(String,Integer,_returns=Array(String))
>     def say_hello(self,name,times):
>         results = []
>         for i in range(0,times):
>             results.append('Hello, %s'%name)
>         return results
>
> if __name__=='__main__':
>     print 'server begin running...'
>     try:
>         from wsgiref.simple_server import make_server
>         soap_application = Application([HelloWorldService], 'tns')
>
>         wsgi_application = wsgi.Application(soap_application)
>         server = make_server('localhost', 7789, wsgi_application)
>         server.serve_forever()
>     except ImportError:
>         print "Error: example server code requires Python >= 2.5"
>
> # suds.py
> import suds
> def test_soaplib():
>     
>     url = "http://localhost:7789/?wsdl"
>     client = suds.client.Client(url,cache=None)
>     print 'client', client
>     output = client.service.say_hello('jia',3)
>     print 'output', output
>
> when you invoke sus.py , it takes much time and a long time later
> returns the right result
> ”output (stringArray){
>    string[] =
>       "Hello, jia",
>       "Hello, jia",
>       "Hello, jia",
>  }
>> or the exception below(it‘s not present exceptions as follows. most of
> time it return the result successfully after 2 or 3 minutes).
>
> Traceback (most recent call last):
>   File "suds_client.py", line 774, in <module>
>     test_soaplib()
>   File "suds_client.py", line 627, in test_soaplib
>     client = suds.client.Client(url,cache=None)
>   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 194, in __init__
>     self.build_schema()
>   File
> "/usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/wsdl.py",
> line 255, in build_schema
>     self.schema = container.load()
>   File
> "/usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/schema.py",
> line 90, in load
>     child.open_imports()
>   File
> "/usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/schema.py",
> line 277, in open_imports
>     imported = imp.open()
>   File
> "/usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/sxbasic.py",
> line 608, in open
>     result = self.download()
>   File
> "/usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/sxbasic.py",
> line 628, in download
>     return self.schema.instance(root, url)
>   File
> "/usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/schema.py",
> line 367, in instance
>     return Schema(root, baseurl, self.options)
>   File
> "/usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/schema.py",
> line 200, in __init__
>     self.open_imports()
>   File
> "/usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/schema.py",
> line 277, in open_imports
>     imported = imp.open()
>   File
> "/usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/sxbasic.py",
> line 608, in open
>     result = self.download()
>   File
> "/usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/sxbasic.py",
> line 626, in download
>     root = Parser(transport).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 69, in open
>     fp = self.__open(u2request)
>   File
> "/usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/transport/http.py",
> line 107, in __open
>     return self.urlopener.open(u2request)
>   File "/usr/lib/python2.6/urllib2.py", line 391, in open
>     response = self._open(req, data)
>   File "/usr/lib/python2.6/urllib2.py", line 409, in _open
>     '_open', req)
>   File "/usr/lib/python2.6/urllib2.py", line 369, in _call_chain
>     result = func(*args)
>   File "/usr/lib/python2.6/urllib2.py", line 1161, in http_open
>     return self.do_open(httplib.HTTPConnection, req)
>   File "/usr/lib/python2.6/urllib2.py", line 1134, in do_open
>     r = h.getresponse()
>   File "/usr/lib/python2.6/httplib.py", line 986, in getresponse
>     response.begin()
>   File "/usr/lib/python2.6/httplib.py", line 391, in begin
>     version, status, reason = self._read_status()
>   File "/usr/lib/python2.6/httplib.py", line 355, in _read_status
>     raise BadStatusLine(line)
>
> # okay, the problem is why sometimes the client return the exception
> and most of time return the correct results some minutes later?
>
> Thanks for your time and concentration. Any relay is welcome.
>
> -- Jia Xiaolei
>
>
> _______________________________________________
> Soap mailing list
> Soap at python.org
> http://mail.python.org/mailman/listinfo/soap

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/soap/attachments/20111206/9bb95644/attachment-0001.html>


More information about the Soap mailing list