How to make named items in SOAP web service response in Flask/Spyne Python?

↘锁芯ラ 提交于 2020-01-24 21:24:07

问题


I have written a web server using Flask Enterprise library of python which is going to be a simulator of some web server application. I got the idea for first implementation from this project.

import os
import string
import random
from flaskext.enterprise import Enterprise
from flask import Flask, render_template


CUR_PATH = os.getcwd()

# config Flask
app = Flask(__name__, template_folder='../templates/')

# config Flask Enterprise
enterprise = Enterprise(app)
String = enterprise._sp.String
Integer = enterprise._sp.Integer
Boolean = enterprise._sp.Boolean
Array = enterprise._scls.Array

send_status = 0
msg_status = 6


class Service(enterprise.SOAPService):

    __soap_target_namespace__ = 'MyNS'  # namespace for soap service
    __soap_server_address__ = '/soap'   # address of soap service

    @enterprise.soap(String, String, String,
                     String, Integer, Integer, Integer,
                     _returns=(String, Integer))
    def sendSms(self, sourceAddresses, destinationAddresses, msgBody,
                msgEncoding, groupId, groupWeight, sourceType):
        return (''.join(random.sample(string.replace(string.digits, '0', ''), 8)), send_status)

    @enterprise.soap(Integer, _returns=(String, String, String, Integer, Integer))
    def getSmsDeliveryStatus(self, msgIds):
        return ('0', ''.join(random.sample(string.replace(string.digits, '0', ''), 8)),
                ''.join(random.sample(string.replace(string.digits, '0', ''), 8)), msgIds, msg_status)


@app.route('/')
def index_page():
    """ The index page
    """
    return render_template("index.html")


if __name__ == '__main__':
    port = int(os.environ.get('PORT', 5000))
    app.debug = True
    app.run(host='0.0.0.0', port=port)

I should implement two requirements to provide the exact interface of the web server which I want to simulate:

  1. The simulator should be able to receive/send more than one occurrences of inputs/outputs; which implies that I can send the web server for example three sourceAddresses tags. Using list of strings (Array(String)) as type changes the type of the input in the WSDL to list which is invalid.
  2. The simulator should send output values with specific names; in my version, it uses the pattern ${methodName} + Result + ${index} to name output values. I want to name them myself.

Any help?

EDIT 1: I tried Spyne too; I have same problems with that.

来源:https://stackoverflow.com/questions/44941419/how-to-make-named-items-in-soap-web-service-response-in-flask-spyne-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!