Python SUDS不包含调用

时间:2015-12-31 17:21:59

标签: python parameter-passing suds

我是Python和suds的新手。使用SOAP UI,对我的服务的调用如下所示:

<soapenv:Envelope 
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:ns="<URL to service>" 
    xmlns:ns1="<URL to second namespace>">
   <soapenv:Header/>
   <soapenv:Body>
      <ns:AuthenticateCaller>
         <!--Optional:-->
         <ns:request>
            <ns1:LoanAccountNumber>292206816</ns1:LoanAccountNumber>
         </ns:request>
      </ns:AuthenticateCaller>
   </soapenv:Body>
</soapenv:Envelope>

我尝试使用suds进行以下操作:

from suds.xsd.doctor import ImportDoctor, Import
imp = Import(<URL to service>)
imp.filter.add(<URL to second namespace>)
doctor = ImportDoctor(imp)
client = Client(url, doctor=doctor)
client.service.AuthenticateCaller(LoanAccountNumber='292206816')

生成的XML如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope 
    xmlns:ns0="<URL to service>" 
    xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/
envelope/">
   <SOAP-ENV:Header/>
   <ns1:Body>
      <ns0:AuthenticateCaller/>
   </ns1:Body>
</SOAP-ENV:Envelope>

它缺少调用中的LoanAccountNumber参数,该参数是API的关键。它也缺少我认为ImportDoctor应修复的第二个命名空间。

我的问题是,我错过了LoanAccountNumber未包含在API调用中。

1 个答案:

答案 0 :(得分:1)

以下说明似乎对您有所帮助:

首先,您必须在代码中打印Client即时client的即时消息,所以您会看到以下内容:

Suds ( https://fedorahosted.org/suds/ )  version: 0.4 GA  build: R699-20100913

Service ( YourService_cmV6YW9ubGluZS5uZXQ= )  tns="http://www.yourservice.com/soap/YourService_cmV6YW9ubGluZS5uZXQ="
   Prefixes (1)
  ns0 = "http://schemas.xmlsoap.org/soap/encoding/"
   Ports (1):
  (YourService_cmV6YW9ubGluZS5uZXQ=Port)
     Methods (2):
        your_method(xs:string _your_param)
     Types (48):
        ns0:Array
        ns0:ENTITIES
        ns0:ENTITY
        ns0:ID
        ns0:NOTATION
        ns0:Name
        ns0:QName
        ns0:Struct
        ns0:anyURI
        ns0:arrayCoordinate
        ns0:base64
        ns0:base64Binary
        ns0:boolean
        ns0:byte
        ns0:date
        ns0:dateTime
        ns0:decimal
        ns0:double
        ns0:duration
        ns0:float
        ns0:hexBinary
        ns0:int
        ns0:integer
        ns0:language
        ns0:long
        ns0:negativeInteger
        ns0:positiveInteger
        ns0:short
        ns0:string
        ns0:time
        ns0:token

然后找到适当的参数类型,并按以下方式创建参数:

your_param = client.factory.create("ns0:string")
your_param.value = your_value

(复杂的类型遵循复杂的方式!)

现在,您可以按如下方式调用您的方法:

client.service.your_method(your_param)

享受吧!