我正在尝试使用 python spyne 库创建一个肥皂服务器。我真的不明白如何配置服务器以接收正在发送的数据,因为我收到错误。
请为我提供有关解决此问题的一些帮助、提示和反馈。
当我发布粘贴在下面的代码时,我得到:
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'
这是我的肥皂服务器将收到的查询。
<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><string>: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>