from spyne import Application,rpc,ServiceBase,Iterable,Integer,Unicode
from spyne.protocol.soap import Soap11,Soap12
from spyne.server.wsgi import WsgiApplication
class HelloWorldService1(ServiceBase):
@rpc(Unicode,Integer,_returns=Iterable(Unicode))
def say_hello11(ctx,name,times):
"""Docstrings for service methods appear as documentation in the wsdl.
<b>What fun!</b>
@param name the name to say hello to
@param times the number of times to say hello
@return the completed array
"""
for i in range(times):
yield u'say_hello11 : Hello,%s' % name
@rpc(Unicode,Integer,_returns=Iterable(Unicode))
def say_hello12(ctx,name,times):
"""Docstrings for service methods appear as documentation in the wsdl.
<b>What fun!</b>
@param name the name to say hello to
@param times the number of times to say hello
@return the completed array
"""
for i in range(times):
yield u'say_hello12 : Hello,%s' % name
class HelloWorldService2(ServiceBase):
@rpc(Unicode,Integer,_returns=Iterable(Unicode))
def say_hello21(ctx,name,times):
"""Docstrings for service methods appear as documentation in the wsdl.
<b>What fun!</b>
@param name the name to say hello to
@param times the number of times to say hello
@return the completed array
"""
for i in range(times):
yield u'say_hello21 : Hello,%s' % name
@rpc(Unicode,Integer,_returns=Iterable(Unicode))
def say_hello22(ctx,name,times):
"""Docstrings for service methods appear as documentation in the wsdl.
<b>What fun!</b>
@param name the name to say hello to
@param times the number of times to say hello
@return the completed array
"""
for i in range(times):
yield u'say_hello22 : Hello,%s' % name
application = Application([HelloWorldService1,HelloWorldService2],'http://schemas.xmlsoap.org/soap/envelope',in_protocol=Soap11(validator='lxml'),out_protocol=Soap11())
wsgi_application = WsgiApplication(application)
if __name__ == '__main__':
import logging
from wsgiref.simple_server import make_server
logging.basicConfig(level=logging.DEBUG)
logging.getLogger('spyne.protocol.xml').setLevel(logging.DEBUG)
logging.info("listening to http://192.168.1.68:8000")
logging.info("wsdl is at: http://192.168.1.68:8000/?wsdl")
server = make_server('192.168.1.68',8000,wsgi_application)
server.serve_forever()
python3.6 + suds-jurko 调用上述webservice
from suds.client import Client
url = 'http://192.168.1.68:8000/?wsdl'
client = Client(url)
print(client)
res = client.service.say_hello11('zhangsan',1)
print(res)
print('='*20)
# res = client.service.say_hello12('lisi',2)
# print(res)
# print('='*20)
# res = client.service.say_hello21('wangwu',3)
# print(res)
# print('='*20)
# res = client.service.say_hello22('luliu',4)
# print(res)