我在使用soaplib时遇到问题。 我通过网络服务提供了以下功能:
@soap(Integer, Integer, _returns=Integer)
def test(self, n1, n2):
return n1 + n2
生成的 WSDL 文件中数据类型的相应声明是
<xs:complexType name="test">
<xs:sequence>
<xs:element name="n1" type="xs:integer" minOccurs="0" nillable="true"/>
<xs:element name="n2" type="xs:integer" minOccurs="0" nillable="true"/>
</xs:sequence>
</xs:complexType>
<xs:complexType> name="testResponse">
<xs:sequence>
<xs:element name="testResult" type="xs:integer" minOccurs="0" nillable="true"/>
</xs:sequence>
</xs:complexType>
当我使用某些 IDE(Visual Studio、PowerBuilder)从该 WSDL 文件生成代码时,无论使用什么 IDE,它都会生成两个用于 test 和 testResponse 的类,其属性是字符串。
有谁知道我是否可以调整我的 Python 声明,以便避免复杂类型并在客户端获取真正的整数数据类型?
最佳答案
我检查了你的代码,但得到了相同的输出。我正在使用suds解析值。
In [3]: from suds import client
In [4]: cl = client.Client('http://localhost:8080/?wsdl')
In [5]: cl.service.test(10,2)
Out[5]: 12
但是当我检查该值的类型时。
In [6]: type(cl.service.test(10,2))
Out[6]: <class 'suds.sax.text.Text'>
因此 SOAPLIB 将返回字符串,但您可以根据该数据的类型对其进行转换。
我通过写这个来检查回复
@soap(_returns=Integer)
def test(self):
return 12
所以我进入 Firefox 响应的 SOA 客户端插件
<?xml version='1.0' encoding='utf-8'?>
<senv:Envelope
xmlns:wsa="http://schemas.xmlsoap.org/ws/2003/03/addressing"
xmlns:plink="http://schemas.xmlsoap.org/ws/2003/05/partner-link/"
xmlns:xop="http://www.w3.org/2004/08/xop/include"
xmlns:senc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:s12env="http://www.w3.org/2003/05/soap-envelope/"
xmlns:s12enc="http://www.w3.org/2003/05/soap-encoding/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:senv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<senv:Body>
<tns:testResponse>
<tns:testResult>
12
</tns:testResult>
</tns:testResponse>
</senv:Body>
</senv:Envelope>
从 XML 中您无法获取原始整数数据。
关于python - 使用soaplib生成的错误(?)数据类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7710846/