为什么我的简单计算器 Postman 请求不起作用?

chy5wohz  于 2023-01-13  发布在  Postman
关注(0)|答案(1)|浏览(180)

我是 Postman 和网络服务的新手,我正在尝试使用 Postman 和WSDL实现一个简单的计算器网络服务。问题是我不知道如何通过 Postman 的正文或标题发送请求。

第一节第一节第一节第二节第一节
我的python代码是:从spyne导入应用程序,rpc,服务库,整数,双精度从spyne.protocol.soap导入Soap11从spyne.server.wsgi导入wsgiApplication

class CalculatorService(ServiceBase):

    @rpc(Integer, Integer, _returns=Integer)
    def addition(ctx, a, b):
        return a + b

    @rpc(Integer, Integer, _returns=Integer)
    def substraction(ctx, a, b):
        return a - b

    @rpc(Integer, Integer, _returns=Integer)
    def multiplication(ctx, a, b):
        return a * b

    @rpc(Integer, Integer, _returns=Double)
    def division(ctx, a, b):
        return a / b

application = Application([CalculatorService], 'services.calculator.soap',
                          in_protocol=Soap11(validator='lxml'),
                          out_protocol=Soap11())

wsgi_application = WsgiApplication(application)

if __name__ == '__main__':
    import logging

    from wsgiref.simple_server import make_server

    logging.basicConfig(level=logging.INFO)
    logging.getLogger('spyne.protocol.xml').setLevel(logging.INFO)

    logging.info("listening to http://127.0.0.1:8000")
    logging.info("wsdl is at: http://127.0.0.1:8000/?wsdl")

    server = make_server('127.0.0.1', 8000, wsgi_application)
    server.serve_forever()

已尝试完成标头参数,但似乎无法了解其不起作用的原因。

cdmah0mi

cdmah0mi1#

缺少输入参数和名称服务services.calculator.soap
这是附加输入

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="services.calculator.soap">
   <soapenv:Header/>
   <soapenv:Body>
      <ser:addition>
         <!--Optional:-->
         <ser:a>6</ser:a>
         <!--Optional:-->
         <ser:b>9</ser:b>
      </ser:addition>
   </soapenv:Body>
</soapenv:Envelope>

SoapUI让生活更轻松。以下是步骤

1 Python代码保存为simple-calculator.py
from spyne import Application, rpc, ServiceBase, Integer, Double

from spyne.protocol.soap import Soap11
from spyne.server.wsgi import WsgiApplication

class CalculatorService(ServiceBase):

    @rpc(Integer, Integer, _returns=Integer)
    def addition(ctx, a, b):
        return a + b

    @rpc(Integer, Integer, _returns=Integer)
    def substraction(ctx, a, b):
        return a - b

    @rpc(Integer, Integer, _returns=Integer)
    def multiplication(ctx, a, b):
        return a * b

    @rpc(Integer, Integer, _returns=Double)
    def division(ctx, a, b):
        return a / b

application = Application([CalculatorService], 'services.calculator.soap',
                          in_protocol=Soap11(validator='lxml'),
                          out_protocol=Soap11())

wsgi_application = WsgiApplication(application)

if __name__ == '__main__':
    import logging

    from wsgiref.simple_server import make_server

    logging.basicConfig(level=logging.INFO)
    logging.getLogger('spyne.protocol.xml').setLevel(logging.INFO)

    logging.info("listening to http://127.0.0.1:8000")
    logging.info("wsdl is at: http://127.0.0.1:8000/?wsdl")

    server = make_server('127.0.0.1', 8000, wsgi_application)
    server.serve_forever()

#2安装并运行它

pip install spyne
python simple-calculator.py

#3通过浏览器检查WSDL是否正常工作。

http://localhost:8000/?wsdl

#4通过SoapUI创建SOAP项目

#5通过单击addition中的Request 1创建SOAP输入XML

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="services.calculator.soap">
   <soapenv:Header/>
   <soapenv:Body>
      <ser:addition>
         <!--Optional:-->
         <ser:a>?</ser:a>
         <!--Optional:-->
         <ser:b>?</ser:b>
      </ser:addition>
   </soapenv:Body>
</soapenv:Envelope>

#6输入和后运行,然后按绿色运行按钮

结果会返回到面板的右边。如果你把它复制/粘贴到VS代码中(右边的红框)并格式化文档,它会是一个可读性更强的漂亮格式。

之前

<?xml version='1.0' encoding='UTF-8'?>
<soap11env:Envelope xmlns:soap11env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="services.calculator.soap"><soap11env:Body><tns:additionResponse><tns:additionResult>13</tns:additionResult></tns:additionResponse></soap11env:Body></soap11env:Envelope>

之后

<soap11env:Envelope xmlns:soap11env="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:tns="services.calculator.soap">
    <soap11env:Body>
        <tns:additionResponse>
            <tns:additionResult>15</tns:additionResult>
        </tns:additionResponse>
    </soap11env:Body>
</soap11env:Envelope>

divisionmultiplicationsubtraction的步骤相同

Postman 中的division

参考文献

Work with WSDLs in SoapUI
spyne examples

相关问题