2017-03-31 83 views
0

我有一个WSDL文件无法通过认证paramethers

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:TestWebService"> 
    <soapenv:Header> 
     <urn:AuthenticationInfo> 
     <urn:userName>test</urn:userName> 
     <urn:password>test</urn:password> 
     <!--Optional:--> 
     <urn:authentication></urn:authentication> 
     <!--Optional:--> 
     <urn:locale></urn:locale> 
     <!--Optional:--> 
     <urn:timeZone></urn:timeZone> 
     </urn:AuthenticationInfo> 
    </soapenv:Header> 
    <soapenv:Body> 
     <urn:Pokupi> 
     <urn:Request_ID__c>000000000000141</urn:Request_ID__c> 
     </urn:Pokupi> 
    </soapenv:Body> 
</soapenv:Envelope> 

我在Python代码如下:

#import zeep 
from suds.client import Client 
from suds import WebFault 
from suds.sax.element import Element 

url = 'http://bmc2012.comtrade.co.yu:8080/arsys/WSDL/public/BMC2012/TestWebService' 
user = "test" 
password = "test" 

ssnp = Element("xsi:AuthenticationInfo").append(Element('xsi:userName').setText(user)) 
ssnp = Element("xsi:AuthenticationInfo").append(Element('xsi:password').setText(password)) 
client = Client(url) 
client.set_options(soapheaders=ssnp) 

record = client.factory.create('Pokupi') 
result = client.service.Pokupi(record) 
print result 

#client = zeep.Client(url) 
#print (client.service.Pokupi('000000000000141')) 

而不是在响应中获取数据,我不断收到错误信息: 控制记录中必须提供用户名

我试过zeep和suds库,但我无法传递此消息。当我在SOPA用户界面内进行此调用时,我没有遇到任何错误。 任何想法我做错了什么?

回答

0

我遇到过类似的问题。以下是我跟着来解决问题的步骤(我用“ZEEP”第三方模块来解决这个问题):

  1. 运行以下命令来了解我的WSDL

    python -mzeep **wsdl_url**

    (在你的情况wsdl_urlhttp://bmc2012.comtrade.co.yu:8080/arsys/WSDL/public/BMC2012/TestWebService

  2. 我们可以搜索字符串“SERV冰:”。在下面我们可以看到我们的操作名称(我猜你的操作是“Pokupi”)。

  3. 对于我的操作,我发现下面的条目:

    MyOperation(param1 xsd:string, _soapheaders={parameters: ns0:AuthenticationInfo})

    清楚地传达了,我必须通过一个字符串PARAM和使用kwargs “_soapheaders”

  4. 有了这一个auth PARAM我开始知道我必须将我的身份验证元素作为_soapheaders参数传递给MyOperation函数。

  5. 创建auth元素:

    auth_ele = client.get_element('ns0:AuthenticationInfo') auth = auth_ele(userName='me', password='mypwd')

  6. 通过了身份验证到我的操作:

    cleint.service.MyOperation('param1_value', _soapheaders=[auth])

我得到了预期的结果。虽然这是一个迟到的回复,但我认为这会帮助那些像我一样受苦的人。