【python】-web services

一、服务端 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 = """
                  
                   
                   
                1aa8c155-dcfe-4472-9bfd-55c38c6c47fa   
                40CE39723A270D4EB9F0D98A234C10A3  
                    
                 
                  """
        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'))

你可能感兴趣的:(【python】-web services)