Hi Burak,
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 SimpleWSGISoapAppfrom soaplib.service import soapmethodfrom soaplib.serializers.clazz import ClassSerializerfrom soaplib.serializers.primitive import String, Integer, Array, DateTime
class SMS(ClassSerializer):class types:mobile = Stringcontent = 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_clientclient = make_service_client('http://localhost:7789/' ,SMSService())return client
if __name__=='__main__':try:from wsgiref.simple_server import make_serverserver = make_server('localhost', 7789,SMSService())server.serve_forever()except ImportError:print "Error: example server code requires Python >= 2.5"
#file-name: suds_client.pyimport suds
def test_soaplib3():import logginglogging.basicConfig(level=logging.ERROR)
url = "http://localhost:7789/?wsdl"client = suds.client.Client(url,cache=None)print 'client', clientoutput = client.service.get_sms('jia')print 'output', output
#NOTE: Certainly, it's okay. Below is the output:
#output:clientSuds ( 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):SMSSMSArrayget_smsget_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 SMSServicefrom soaplib_server3 import make_clientimport lxml.etree as et
a = make_client()ret = a.get_sms('jia')print 'ret:', retprint '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.pyimport soaplibfrom soaplib.core.service import soapfrom soaplib.core.service import rpc, DefinitionBasefrom soaplib.core.model.primitive import String, Integerfrom soaplib.core.server import wsgifrom soaplib.core.model.clazz import Arrayfrom soaplib.core import Applicationclass 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_serversoap_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.pyimport sudsdef test_soaplib():url = "http://localhost:7789/?wsdl"client = suds.client.Client(url,cache=None)print 'client', clientoutput = 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_soaplibclient = 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_schemaself.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 loadchild.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_importsimported = imp.open()File "/usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/sxbasic.py", line 608, in openresult = self.download()File "/usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/sxbasic.py", line 628, in downloadreturn 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 instancereturn 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_importsimported = imp.open()File "/usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/sxbasic.py", line 608, in openresult = self.download()File "/usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/xsd/sxbasic.py", line 626, in downloadroot = 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 parsefp = 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 openreturn 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 openfp = 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 __openreturn self.urlopener.open(u2request)File "/usr/lib/python2.6/urllib2.py", line 391, in openresponse = 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_chainresult = func(*args)File "/usr/lib/python2.6/urllib2.py", line 1161, in http_openreturn self.do_open(httplib.HTTPConnection, req)File "/usr/lib/python2.6/urllib2.py", line 1134, in do_openr = h.getresponse()File "/usr/lib/python2.6/httplib.py", line 986, in getresponseresponse.begin()File "/usr/lib/python2.6/httplib.py", line 391, in beginversion, status, reason = self._read_status()File "/usr/lib/python2.6/httplib.py", line 355, in _read_statusraise 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@python.org http://mail.python.org/mailman/listinfo/soap