一、服務(wù)端 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'))
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。