Python Spyne - WSDL服务器 - 验证根目录没有可用的匹配全局声明

时间:2013-09-12 10:24:28

标签: python soap wsdl suds spyne

我正在尝试使用python spyne库创建一个soap服务器。我真的不明白如何配置服务器以接收正在发送的数据,因为我收到了错误。

请向我提供一些有关解决此问题的帮助,提示和反馈。

当我发布下面粘贴的代码时,我得到:

No matching global declaration available for the validation root.

当我使用suds发送一些数据时,我得到了:

imp = Import('http://schemas.xmlsoap.org/soap/encoding/',
             location='http://schemas.xmlsoap.org/soap/encoding/')

imp.filter.add('http://localhost:8000/sms/receive/')

client = suds.client.Client('http://localhost:8000/sms/receive/')

print client
data = dict(id=1231412,
            name="tester",
            operator="nokia",
            to="4879293213",
            text="4879293213",
            numberOfParts=1,
            )
print client.service.ReceiveSms(data)
suds.TypeNotFound: Type not found: 'to'

这是我的soap服务器将收到的查询。

<env:Header/>
<env:Body>
    <ns1:ReceiveSms xmlns:ns1="http://com.blablabla.webservice.receiver/webservice">
    <Sms_1>
        <id>25094332348431</id>
        <from>48123123123</from>
        <operator>P4</operator>
        <to>481231231234</to>
        <text>test</text>
        <numberOfParts>1</numberOfParts>
    </Sms_1>
</ns1:ReceiveSms>
</env:Body>
</env:Envelope>

这是我的WSDL:

<?xml version="1.0"?>
<definitions targetNamespace="spyne.examples.hello" name="Application">
    <types>
        <schema targetNamespace="server" elementFormDefault="qualified">
            <complexType name="ResponseArray">
                <sequence>
                    <element name="Response" type="s0:Response" minOccurs="0" maxOccurs="unbounded" nillable="true"/>
                </sequence>
            </complexType>
            <complexType name="Response">
                <sequence>
                    <element name="name" type="xs:string" minOccurs="0" nillable="true"/>
                    <element name="text" type="xs:string" minOccurs="0" nillable="true"/>
                    <element name="numberOfParts" type="xs:integer" minOccurs="0" nillable="true"/>
                    <element name="to" type="xs:string" minOccurs="0" nillable="true"/>
                    <element name="operator" type="xs:string" minOccurs="0" nillable="true"/>
                    <element name="id" type="xs:long" minOccurs="0" nillable="true"/>
                </sequence>
            </complexType>
            <element name="Response" type="s0:Response"/>
            <element name="ResponseArray" type="s0:ResponseArray"/>
        </schema>
        <schema targetNamespace="spyne.examples.hello" elementFormDefault="qualified">
            <import namespace="server"/>
            <complexType name="ReceiveSmsResponse">
                <sequence>
                    <element name="ReceiveSmsResult" type="xs:string" minOccurs="0" nillable="true"/>
                </sequence>
            </complexType>
            <complexType name="ReceiveSms">
                <sequence>
                    <element name="Sms_1" type="s0:ResponseArray" minOccurs="0" nillable="true"/>
                </sequence>
            </complexType>
            <element name="ReceiveSms" type="tns:ReceiveSms"/>
            <element name="ReceiveSmsResponse" type="tns:ReceiveSmsResponse"/>
        </schema>
    </types>
    <message name="ReceiveSms">
        <part name="ReceiveSms" element="tns:ReceiveSms"/>
    </message>
    <message name="ReceiveSmsResponse">
        <part name="ReceiveSmsResponse" element="tns:ReceiveSmsResponse"/>
    </message>
    <service name="ReceiverService">
        <port name="Application" binding="tns:Application">
            <address location="http://localhost:8000/sms/receive/"/>
        </port>
    </service>
    <portType name="Application">
        <operation name="ReceiveSms" parameterOrder="ReceiveSms">
            <input name="ReceiveSms" message="tns:ReceiveSms"/>
            <output name="ReceiveSmsResponse" message="tns:ReceiveSmsResponse"/>
        </operation>
    </portType>
    <binding name="Application" type="tns:Application">
        <binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <operation name="ReceiveSms">
            <operation soapAction="ReceiveSms" style="document"/>
            <input name="ReceiveSms">
                <body use="literal"/>
            </input>
            <output name="ReceiveSmsResponse">
                <body use="literal"/>
            </output>
        </operation>
    </binding>
</definitions>

我的代码:

class ReceiverService(ServiceBase):
    @srpc(Array(Response), _returns=Unicode)
    def ReceiveSms(Sms_1):
        print Sms_1
        return Sms_1


application = Application([ReceiverService],
    tns='spyne.examples.hello',
    in_protocol=Soap11(validator='lxml'),
    out_protocol=Soap11()
    )

hello_app = csrf_exempt(DjangoApplication(application))

XML响应:

<?xml version='1.0' encoding='UTF-8'?>
<senv:Envelope 
    xmlns:senv="http://schemas.xmlsoap.org/soap/envelope/">
    <senv:Body>
        <senv:Fault>
            <faultcode>senv:Client.SchemaValidationError</faultcode>
            <faultstring>&lt;string&gt;:2:0:ERROR:SCHEMASV:SCHEMAV_CVC_ELT_1: Element '{http://localhost:8000/types/}receiveSms': No matching global declaration available for the validation root.</faultstring>
            <faultactor></faultactor>
        </senv:Fault>
    </senv:Body>
</senv:Envelope>

1 个答案:

答案 0 :(得分:0)

假设网址正确并且Response对象已正确定义,则以下内容应该有效:

client = suds.client.Client('http://localhost:8000/sms/receive/?wsdl')
resp = client.factory.create('{spyne.examples.hello}Response')
resp.id = 5
# (...)
print client.service.ReceiveSms(resp)

我对你的建议是始终从最简单的情况开始,然后用小步骤进行迭代。