python开发webservice,SAP端调用

1、使用python开发一个webservice服务端的接口,并暴露出去

     python环境:3.6

    IDE:Eclipse Java EE IDE for Web Developers.

              Version: Oxygen.3a Release (4.7.3a)

               anaconda

需要注意的是:py3和py2的soap的支持包不太一样,py2使用的是BaseHTTPServer,而py3使用的是spyne

2、python webservice服务器端代码

    

'''
Created on 2018年7月16日

@author: lin
'''

# Application is the glue between one or more service definitions, interface and protocol choices.
from spyne import Application
# @rpc decorator exposes methods as remote procedure calls
# and declares the data types it accepts and returns
from spyne import rpc
# spyne.service.ServiceBase is the base class for all service definitions.
from spyne import ServiceBase
# The names of the needed types for implementing this service should be self-explanatory.
from spyne import Iterable, Integer, Unicode
 
from spyne.protocol.soap import Soap11
# Our server is going to use HTTP as transport, It’s going to wrap the Application instance.
from spyne.server.wsgi import WsgiApplication
 
 
# step1: Defining a Spyne Service
class HelloWorldService(ServiceBase):
    @rpc(Unicode, Integer, _returns=Iterable(Unicode))
    def say_hello(self, 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  When returning an iterable, you can use any type of python iterable. Here, we chose to use generators.
        """
 
        for i in range(times):
            yield u'Hello, %s' % name
 
 
# step2: Glue the service definition, input and output protocols
soap_app = Application([HelloWorldService], 'spyne.examples.hello.soap',
                       in_protocol=Soap11(validator='lxml'),
                       out_protocol=Soap11())
 
# step3: Wrap the Spyne application with its wsgi wrapper
wsgi_app = WsgiApplication(soap_app)
 
if __name__ == '__main__':
    import logging
 
    from wsgiref.simple_server import make_server
 
    # configure the python logger to show debugging output
    logging.basicConfig(level=logging.DEBUG)
    logging.getLogger('spyne.protocol.xml').setLevel(logging.DEBUG)
 
    logging.info("listening to http://saplh:8000")
    logging.info("wsdl is at: http://saplh:8000/?wsdl")
 
    # step4:Deploying the service using Soap via Wsgi
    # register the WSGI application as the handler to the wsgi server, and run the http server
    server = make_server('saplh', 8000, wsgi_app)
    server.serve_forever()
3、无问题后执行

     之后打开http://saplh:8000http://saplh:8000/?wsdl能正常显示如下地址的话表示接口成功暴露


4、使用工具测试接口,这里使用的是soapui来测试

     soapui 版本5.3

工具测试无问题



5、使用sap去调用,首先现在SAP端的服务器去调用此接口,看是否可以调通,我第一次调用的时候失败了,原因是端口没开,而且没用域名而使用的ip地址的方式。

    在sap服务器端测试wsdl,可以正常调通,接下来就是导入wsdl到sap内即可

python代码参考自https://www.cnblogs.com/guanfuchang/p/5985070.html

posted @   linhuang  阅读(39)  评论(0编辑  收藏  举报  
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
点击右上角即可分享
微信分享提示