2017-06-02 67 views
0

我試圖訪問使用Zeep如何遵守WSDL

有一個公開的WSDL SOAP Web服務定義的策略,和testing WSDL(具有自簽名的證書)

我碼測試(從測試地點)是:

from requests import Session 
from zeep import Client 
from zeep.transports import Transport 
from zeep.wsse.username import UsernameToken 
import xml.dom.minidom 

WS_USER_NAME = '<username>' 
WS_PASSWORD = '<password>' 
WS_WSDL = 'https://pre.ipddb.org/WS/Services/IpdDownloadService.svc?wsdl' 

session = Session() 
session.verify = False 
transport = Transport(session=session, 
         operation_timeout=10) 
client = Client(wsdl=WS_WSDL, 
       wsse=UsernameToken(WS_USER_NAME, WS_PASSWORD), 
       transport=transport) 

with client.options(raw_response=True): 

    response = client.service.Search(strNames='Rick Astley') 
    xml = xml.dom.minidom.parseString(response._content) 
    print xml.toprettyxml() 

我的回答是回來爲:

<?xml version="1.0" ?> 
<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope"> 
    <s:Header> 
     <a:Action s:mustUnderstand="1">http://www.w3.org/2005/08/addressing/soap/fault</a:Action> 
     <a:RelatesTo>urn:uuid:5ffbeb15-913b-41ec-a2ef-556c131c07eb</a:RelatesTo> 
    </s:Header> 
    <s:Body> 
     <s:Fault> 
      <s:Code> 
       <s:Value>s:Sender</s:Value> 
       <s:Subcode> 
        <s:Value xmlns:a="http://schemas.xmlsoap.org/ws/2005/02/sc">a:BadContextToken</s:Value> 
       </s:Subcode> 
      </s:Code> 
      <s:Reason> 
       <s:Text xml:lang="es-ES">The message could not be processed. This is most likely because the action 'https://www.ipddb.org/ws/IpdDownloadService/Search' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding.</s:Text> 
      </s:Reason> 
     </s:Fault> 
    </s:Body> 
</s:Envelope> 

我從Web服務的所有者提供了一個用戶名和密碼,所以我知道我需要提供,但必須有其他東西我缺少。我相信它與WSDL中定義的策略有關,但Web服務不提供任何文檔方面的內容。

我是SOAP的新手,但是WSDL中是否有足夠的空間來確定他們需要遵守的策略?

我可以使用Zeep來完成所有的政策嗎?

我是否需要維護Web服務的人員提供更多信息?

回答

0

不是說這是對你問題的直接回答,但是當我必須發出肥皂請求時,我喜歡使用soapui來熟悉API。

一旦您爲soapui提供了一個WSDL,它將自動生成所有必需的參數以獲得正確的請求。通過這樣做,您可以驗證您收到的錯誤是由於系統策略而不是因爲zeep。

+0

我實際上是從[SoapUI](https://www.soapui.org)開始的,得到了​​同樣的錯誤。我的最終目標是使用Zeep,但即使使用SoapUI,我也遇到了這個錯誤 – tkwargs