SOAP Spyne 请求的资源未找到 WSDL

问题描述 投票:0回答:1

这就是我尝试从 Hello World 应用程序开始的原因……不是很成功。我在 python 中用 SPYNE 创建了一个服务器。我总是收到错误的响应“未找到请求的资源 say_helloResponse。如果我删除请求“say_helloResponse”,它也不会找到其他资源。我不明白这一点.. 你能帮忙吗?

main.py


from spyne import Application, rpc, ServiceBase, Iterable, Integer, Unicode

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


class HelloWorldService(ServiceBase):
    @rpc(Unicode, Integer, _returns=Iterable(Unicode))
    def say_hello(ctx, 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 the completed array
        """

        for i in range(times):
            yield u'Hello, %s' % name


application = Application([HelloWorldService], 'spyne.examples.hello.soap',
                          in_protocol=Soap11(validator='lxml'),
                          out_protocol=Soap11(polymorphic=True))

wsgi_application = WsgiApplication(application)


if __name__ == '__main__':
    import logging

    from wsgiref.simple_server import make_server

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

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

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

wsdl

<wsdl:definitions targetNamespace="spyne.examples.hello.soap" name="Application">
<wsdl:types>
<xs:schema targetNamespace="spyne.examples.hello.soap" elementFormDefault="qualified">
<xs:complexType name="stringArray">
<xs:sequence>
<xs:element name="string" type="xs:string" minOccurs="0" maxOccurs="unbounded" nillable="true"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="say_hello">
<xs:sequence>
<xs:element name="name" type="xs:string" minOccurs="0" nillable="true"/>
<xs:element name="times" type="xs:integer" minOccurs="0" nillable="true"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="say_helloResponse">
<xs:sequence>
<xs:element name="say_helloResult" type="tns:stringArray" minOccurs="0" nillable="true"/>
</xs:sequence>
</xs:complexType>
<xs:element name="stringArray" type="tns:stringArray"/>
<xs:element name="say_hello" type="tns:say_hello"/>
<xs:element name="say_helloResponse" type="tns:say_helloResponse"/>
</xs:schema>
</wsdl:types>
<wsdl:message name="say_hello">
<wsdl:part name="say_hello" element="tns:say_hello"/>
</wsdl:message>
<wsdl:message name="say_helloResponse">
<wsdl:part name="say_helloResponse" element="tns:say_helloResponse"/>
</wsdl:message>
<wsdl:service name="HelloWorldService">
<wsdl:port name="Application" binding="tns:Application">
<wsdlsoap11:address location="http://localhost:8008/"/>
</wsdl:port>
</wsdl:service>
<wsdl:portType name="Application">
<wsdl:operation name="say_hello" parameterOrder="say_hello">
<wsdl:documentation>
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 the completed array
</wsdl:documentation>
<wsdl:input name="say_hello" message="tns:say_hello"/>
<wsdl:output name="say_helloResponse" message="tns:say_helloResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="Application" type="tns:Application">
<wsdlsoap11:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="say_hello">
<wsdlsoap11:operation soapAction="say_hello" style="document"/>
<wsdl:input name="say_hello">
<wsdlsoap11:body use="literal"/>
</wsdl:input>
<wsdl:output name="say_helloResponse">
<wsdlsoap11:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
</wsdl:definitions>

要求

<?xml version='1.0' encoding='UTF-8'?>
<senv:Envelope xmlns:tns="spyne.examples.hello.soap" xmlns:senv="http://schemas.xmlsoap.org/soap/envelope/">
  <senv:Body>
    <tns:say_helloResponse>
      <tns:say_helloResult>
        <tns:string>Hello, Dave</tns:string>
        <tns:string>Hello, Dave</tns:string>
        <tns:string>Hello, Dave</tns:string>
        <tns:string>Hello, Dave</tns:string>
        <tns:string>Hello, Dave</tns:string>
      </tns:say_helloResult>
    </tns:say_helloResponse>
  </senv:Body>
</senv:Envelope>

回应


<?xml version='1.0' encoding='UTF-8'?>
<soap11env:Envelope xmlns:soap11env="http://schemas.xmlsoap.org/soap/envelope/"><soap11env:Body><soap11env:Fault><faultcode>soap11env:Client.ResourceNotFound</faultcode><faultstring>Requested resource '{spyne.examples.hello.soap}say_helloResponse' not found</faultstring><faultactor></faultactor></soap11env:Fault></soap11env:Body></soap11env:Envelope>

我在网络上没有发现任何类似的问题,在地面上我需要 python handle soap requests

python soap wsdl spyne
1个回答
0
投票

终于搞定了,请求是false in ground,因为这是预期的响应omg.. 这是正确的要求:

<?xml version='1.0' encoding='UTF-8'?>
<senv:Envelope xmlns:tns="spyne.examples.hello.soap" xmlns:senv="http://schemas.xmlsoap.org/soap/envelope/">
<senv:Header> <RequestHeader>
</RequestHeader>
</senv:Header>
<senv:Body>
<tns:say_hello>
<tns:name>Axel</tns:name>
<tns:times>5</tns:times>
</tns:say_hello>
</senv:Body>
</senv:Envelope> 
© www.soinside.com 2019 - 2024. All rights reserved.