2017-03-27 54 views
0
SOAP Webservice的訪問聯邦數據

我試圖進入瑞士聯邦政府的商業登記的web服務(https://www.bfs.admin.ch/bfs/de/home/register/unternehmensregister/unternehmens-identifikationsnummer/uid-register/uid-schnittstellen.assetdetail.1760903.html通過使用肥皂水在Python

然而他們的文檔是如此複雜和怪異,我有沒有線索如何構建它的工作請求。

我對REST API非常熟悉,但SOAP對我來說是新手。

使用了SoapUI我設法建立一個工作要求:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:uid="http://www.uid.admin.ch/xmlns/uid-wse" xmlns:ns="http://www.ech.ch/xmlns/eCH-0108-f/3" xmlns:ns1="http://www.ech.ch/xmlns/eCH-0098-f/3" xmlns:ns2="http://www.ech.ch/xmlns/eCH-0097-f/2" xmlns:ns3="http://www.ech.ch/xmlns/eCH-0046-f/3" xmlns:ns4="http://www.ech.ch/xmlns/eCH-0044-f/4" xmlns:ns5="http://www.ech.ch/xmlns/eCH-0010-f/6" xmlns:ns6="http://www.ech.ch/xmlns/eCH-0007-f/6"> 
<soapenv:Header/> 
    <soapenv:Body> 
    <uid:Search> 
     <uid:searchParameters> 
     <ns:organisation> 
      <ns1:organisationIdentification> 
       <ns2:organisationName>Beekeeper</ns2:organisationName> 
      </ns1:organisationIdentification> 
     </ns:organisation> 
    </uid:searchParameters> 
    </uid:Search> 
</soapenv:Body> 
</soapenv:Envelope> 

但我未能在Python中實現這一要求。無論我查找什麼教程,我都可以找到如下的東西:

request_data = client.factory.create('s1:CityWeatherRequest') 
request_data.City = "Stockholm" 

如何構建請求的方法如上?

如何創建對SOAP的嵌套請求?

回答

0

你應該看看pyxb

當您基於WSDL架構或XSD文件建立了Python綁定,你可以執行下面的代碼,以使該請求。 wsld顯示你的行動將是什麼。

from pyxb.utils.six.moves.urllib import request as urllib_request 
import pyxb.bundles.wssplat.soap11 as soapenv 

# Create a SOAP envelope from XML 
myenv = soapenv.Envelope(soapenv.Body(myxmlreq)) 

# Create URL, headers and body for the HTTP request 
url="http://www.test.com" 
headers = {'Content-Type': 'text/xml;charset=UTF-8', 
      'Accept-Encoding': 'gzip,deflate', 
      'SOAPAction': "http://test.com/API/Action", # See documentation to learn about the actions 
      'Connection':'close'} # set what your server accepts 
body = myenv.toxml("utf-8") 

# Create the request, send it and receive the response as XML 
uri = urllib_request.Request(url,data=body,headers=headers) 
rxml = urllib_request.urlopen(uri).read() # This is the response XML