鱼C论坛

 找回密码
 立即注册
查看: 919|回复: 2

webservice接口定义数组形参,client调用时如何传参

[复制链接]
发表于 2020-4-23 16:37:33 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
小白的问题:
1、经过各种度娘查到,数组里形参可以使用复杂数据类型ComplexModel,代码如下

api.py
from spyne import Application, rpc, ServiceBase, String, Integer, Float, Array,ComplexModel
from spyne.protocol.soap import Soap11
from spyne.server.wsgi import WsgiApplication
# 将Spyne创建的app 发布为django
from spyne.server.django import DjangoApplication
from django.views.decorators.csrf import csrf_exempt
import redis
from data.enume import repayFund_dict, overdue_dict

# Create your views here.

r = redis.Redis(host='........', port=6379, decode_responses=True)


class Detail(ComplexModel):
    term = Integer
    principal = Float
    interest = Float
    punishmoney = Float
    service_money = Float


class Repay(ServiceBase):
    global res

    @rpc(Integer, Integer, String, Integer, Integer, Integer, Float, Array(Detail), Float, Array(Detail), String,
         _returns=String)
    def RepayOverdue(self, collection_id, orderno_id, borrowid, is_normal, loan_from, is_already, repay_money, detail,
                     write_off_money, write_off_detail, write_off_id):
        if (not collection_id) or (not borrowid) or (not is_already) or (not repay_money) or (not detail):
            res = '必填参数缺失'
        elif borrowid in r.hkeys('overdue_fail_list'):
            res = overdue_dict[r.hget('overdue_fail_list',borrowid)]
        elif borrowid in r.hkeys('overdue_success_list'):
            res = overdue_dict['3']
        else:
            if write_off_money > 0:
                if not write_off_detail:
                    res = '必填参数缺失'
                else:
                    r.hset('overdue_success_list', borrowid, 1)
                    res = overdue_dict['1']
            else:
                r.hset('overdue_success_list', borrowid, 1)
                res = overdue_dict['1']
        print(detail)
        return res


# 命名空间 tns 传入类型Soap11() 传出类型Soap11()
application = Application([Repay], tns='spyne.repay.soap', in_protocol=Soap11(validator='lxml'), out_protocol=Soap11())

# 定义DjangoApplication
item_app = csrf_exempt(DjangoApplication(application))

if __name__ == '__main__':
    import logging
    from wsgiref.simple_server import make_server

    # Wrap the Spyne application with its wsgi wrapper
    wsgi_app = WsgiApplication(application)

    logging.basicConfig(level=logging.DEBUG)
    logging.getLogger('spyne.protocol.xml').setLevel(logging.DEBUG)
    logging.info("listening to http://127.0.0.1:8000")
    logging.info("wsdl is at: http://localhost:8000/?wsdl")
    server = make_server('127.0.0.1', 8000, wsgi_app)
    server.serve_forever()

2、使用python3的suds-py3模块进行访问,代码如下
client.py
from suds.client import Client

client = Client('http://127.0.0.1:8000/WebApi/?wsdl')

detail = client.factory.create('DetailArray')
detail.term = 0
detail.principal = 500.00
detail.interest = 200.00
detail.punishmoney = 300.00
detail.service_money = 0.00

client.service.RepayOverdue(collection_id=111, orderno_id=222, borrowid='2791833', is_normal=1, loan_from=1,
                            is_already=1, repay_money=20000.00, detail=detail,
                            write_off_money=1000, write_off_detail='', write_off_id='333')


3、报错
(DetailArray) not-found
path: "DetailArray", not-found
Traceback (most recent call last):
  File "C:/Users/Administrator/PycharmProjects/lianxi/testApi.py", line 5, in <module>
    detail = client.factory.create('DetailArray')
  File "C:\Users\Administrator\PycharmProjects\lianxi\venv\lib\site-packages\suds\client.py", line 251, in create
    raise TypeNotFound(name)
suds.TypeNotFound: Type not found: 'DetailArray'


请问大佬,要怎么解决?我这是模仿网上例子去写的,不明白client.factory.create()里面传的具体要求,形式,目前是复杂类型+Array组合(DetailArray),是不是一定要这么写
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-4-23 22:11:14 | 显示全部楼层
鱼佬,能不能给解答下,救济
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-4-25 12:34:49 | 显示全部楼层
没人会吗
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-11-26 20:39

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表