【python】-web services
2019-05-02 本文已影响0人
jiandanyaobai
一、服务端 soap_client.py
from spyne.application import Application
from spyne.decorator import srpc
from spyne.service import ServiceBase
from spyne.model.complex import Iterable
from spyne.model.primitive import UnsignedInteger
from spyne.model.primitive import String
from spyne.protocol.soap import Soap11
from spyne.server.wsgi import WsgiApplication
from wsgiref.simple_server import make_server
class HelloWorldService(ServiceBase):
@srpc(String, UnsignedInteger, _returns=String)
def say_hello(name, time):
response = """
<?xml version="1.0" encoding="utf-8"?>
<root>
<systoken>
<syskey>1aa8c155-dcfe-4472-9bfd-55c38c6c47fa</syskey>
<syscode>40CE39723A270D4EB9F0D98A234C10A3</syscode>
</systoken>
<root>
"""
return response
class getErpInfo(ServiceBase):
@srpc(String, _returns=String)
def get_item(name):
return "I am Item!"
@srpc(String, _returns=String)
def get_bom(name):
return "I am Bom!"
if __name__ == "__main__":
app = Application([HelloWorldService,getErpInfo],
'spyne.examples.hello.http',
in_protocol=Soap11(validator='lxml'), out_protocol=Soap11())
wsgi_app = WsgiApplication(app)
server = make_server('127.0.0.1', 7789, wsgi_app)
print("Listening to http://127.0.0.1:7789")
print("WSDL is at: http://localhost:7789/?wsdl")
server.serve_forever()
二、客户端 soap_client.py
from suds.client import Client
hello_client = Client("http://localhost:7789/?wsdl")
print(hello_client)
print(hello_client.service.say_hello('zhouge', 4))
#print(hello_client.service.get_bom('zhouge'))
#print(hello_client.service.get_item('zhouge'))