2017-03-31 85 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])

我得到了預期的結果。雖然這是一個遲到的回覆,但我認爲這會幫助那些像我一樣受苦的人。