美文网首页Python
【python】-web services

【python】-web services

作者: jiandanyaobai | 来源:发表于2019-05-02 11:41 被阅读0次

一、服务端 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'))

相关文章

  • 【python】-web services

    一、服务端 soap_client.py 二、客户端 soap_client.py

  • WebService

    ** 什么是Web Services?** Web Services 是应用程序组件 Web Services 使...

  • 何为AWS?

    全称:Amazon Web Services 亚马逊AWS(Amazon Web Services (AWS) )...

  • WSDL(Travelport Air)

    WSDL 是基于 XML 的用于描述 Web Services 以及如何访问 Web Services 的语言。 ...

  • 使用Python和Boto3自动化AWS

    介绍 在本教程中,我们将研究如何使用Python脚本与Amazon Web Services(AWS)提供的基础架...

  • Jemeter Webservice API测试计划

    在继续本节之前,让我们先了解一些有关Web Services API的关键概念。 Web Services Web...

  • wsdl结构

    服务视图,WebService的服务端点 Web Services的通信协议,还描述Web Services的方法...

  • Blockchain in Web 3.0

    Web 3.0 Highlight Web 1.0 Birth of WWW Web 2.0 Services d...

  • Web Service 关键字

    Web Services 简介 什么是 Web Services 应用程序组件 使用开放协议进行通信 是独立的(s...

  • Web Service教程

    作用:Web Services 可以将应用程序转换为网络应用程序。通过使用 Web Services,您的应用程序...

网友评论

    本文标题:【python】-web services

    本文链接:https://www.haomeiwen.com/subject/ntpmvftx.html