上面的simpleService是自己写的例子,用来说明suds的简单使用。
那么问题来了,实际测试的WebService中定义了多个schema,每个schema拥有不同的并且定义的类型之间互相嵌套,比如:
ns0中定义了A类型的对象,ns1中定义了B类型的对象, 且A对象中有一个属性是B类型的
Class A {
private Class B;
}
通过client.factory.create(‘ns0:A’)构造A对象,报以下错误:
An error occured while building a instance of (ns3:A). As a result
the object you requested could not be constructed. It is recommended
that you construct the type manually using a Suds object.
Please open a ticket with a description of this error.
Reason: Type not found: ‘(B, http://****************, )'
刚开始以为是B在wsdl里没有定义,后来用client.factory.create(‘ns1:B’)来创建B对象是成功的。
搜了很多资料都只是关于怎么使用suds的,没有提及这个问题,苦思冥想,后来突然看到wsdl里<wsld:types>标签下定义了很多个schema,怀疑是不是跨schema引用会找不到类型,所以报了TypeNotFound。于是去找了官方文档,https://fedorahosted.org/suds/
发现创建client对象的方法中有一个options参数,里面有一个bool类型的值autoblend
文档的说明是Flag that ensures that the schema(s) defined within the WSDL import each other.
意思是说这个参数是使得wsdl中定义的schema互相引入,所以可能之前的猜测是正确的
带着试一试的心态改了代码 client = suds.client.Client(url, autoblend = True)
Bingo!成功。