2

I'm trying to call a SOAP service from the Dutch government land register (WSDL here) with PySimpleSoap. So far I did this to connect:

from pysimplesoap.client import SoapClient
client = SoapClient(wsdl='http://www1.kadaster.nl/1/schemas/kik-inzage/20141101/verzoekTotInformatie-2.1.wsdl')

and with the help of an awesome answer by Plamen Petrov I now understand I need to send the xml below using the client.VerzoekTotInformatie() method.

What I do not understand however, is how I can get the desired XML (see below). I can of course build it manually, but I've got the feeling that there is a smarter/more pythonic way of constructing that. Can I use pysimplesoap to construct this message xml?

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.kadaster.nl/schemas/kik-inzage/20141101" xmlns:v20="http://www.kadaster.nl/schemas/kik-inzage/ip-aanvraag/v20141101">
   <soapenv:Header/>
   <soapenv:Body>
      <ns:VerzoekTotInformatieRequest>
         <v20:Aanvraag>
            <v20:berichtversie>?</v20:berichtversie>
            <v20:klantReferentie>ABC</v20:klantReferentie>
            <v20:productAanduiding>?</v20:productAanduiding>
            <v20:Ingang>
               <v20:Object>
                  <v20:IMKAD_KadastraleAanduiding>
                     <v20:gemeente>Amsterdam</v20:gemeente>
                     <v20:sectie>123</v20:sectie>
                     <v20:perceelnummer>456</v20:perceelnummer>
                     <v20:appartementsindex>789</v20:appartementsindex>
                     <v20:deelperceelnummer>10</v20:deelperceelnummer>
                     <v20:AKRKadastraleGemeenteCode>20</v20:AKRKadastraleGemeenteCode>
                  </v20:IMKAD_KadastraleAanduiding>
               </v20:Object>
            </v20:Ingang>
         </v20:Aanvraag>
      </ns:VerzoekTotInformatieRequest>
   </soapenv:Body>
</soapenv:Envelope>

[EDIT]

Following the examples in the docs I now try adding the VerzoekTotInformatieRequest with a berichtversie in it, after which I tried to do a request to the soap-service. But as you can see below, the body still only has an empty <VerzoekTotInformatie> (no Request in it), plus I get a massive error. Any ideas how I can build the message above?

>>> client['VerzoekTotInformatieRequest'] = {'Aanvraag': {'berichtversie': 'yay'}}
>>> c.VerzoekTotInformatie()
INFO:pysimplesoap.client:POST https://service1.kadaster.nl/kik/inzage/20141101/VerzoekTotInformatieService
DEBUG:pysimplesoap.client:SOAPAction: "VerzoekTotInformatie"
Content-length: 378
Content-type: text/xml; charset="UTF-8"
DEBUG:pysimplesoap.client:<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Header/>
<soap:Body>
    <VerzoekTotInformatie xmlns="http://www.kadaster.nl/schemas/kik-inzage/20141101">
    </VerzoekTotInformatie>
</soap:Body>
</soap:Envelope>
DEBUG:pysimplesoap.client:date: Fri, 24 Apr 2015 12:51:05 GMT
status: 404
content-length: 956
content-type: text/html;charset=utf-8
DEBUG:pysimplesoap.client:<html><head><title>JBossWeb/2.0.0.GA_CP05 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;b
ackground-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-s
erif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 404 - </h1><HR si
ze="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The requested resource () is not available.</u></p><HR size="1" noshade="noshade"><h3>JBossWeb/2.0.0.GA_CP05</h3></body></html>
ERROR:pysimplesoap.simplexml:<html><head><title>JBossWeb/2.0.0.GA_CP05 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:whit
e;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,san
s-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 404 - </h1><HR
 size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The requested resource () is not available.</u></p><HR size="1" noshade="noshade"><h3>JBossWeb/2.0.0.GA_CP05</h3></body></html>
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/pysimplesoap/client.py", line 181, in <lambda>
    return lambda *args, **kwargs: self.wsdl_call(attr, *args, **kwargs)
  File "/Library/Python/2.7/site-packages/pysimplesoap/client.py", line 346, in wsdl_call
    return self.wsdl_call_with_args(method, args, kwargs)
  File "/Library/Python/2.7/site-packages/pysimplesoap/client.py", line 370, in wsdl_call_with_args
    response = self.call(method, *params)
  File "/Library/Python/2.7/site-packages/pysimplesoap/client.py", line 262, in call
    jetty=self.__soap_server in ('jetty',))
  File "/Library/Python/2.7/site-packages/pysimplesoap/simplexml.py", line 56, in __init__
    self.__document = xml.dom.minidom.parseString(text)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/dom/minidom.py", line 1928, in parseString
    return expatbuilder.parseString(string)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/dom/expatbuilder.py", line 940, in parseString
    return builder.parseString(string)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xml/dom/expatbuilder.py", line 223, in parseString
    parser.Parse(string, True)
ExpatError: mismatched tag: line 1, column 944
Community
  • 1
  • 1
kramer65
  • 50,427
  • 120
  • 308
  • 488
  • 1
    This is explained in [the docs](https://code.google.com/p/pysimplesoap/w/list). See the [SoapClient](https://code.google.com/p/pysimplesoap/wiki/SoapClient) page, and the examples there. – abarnert Apr 24 '15 at 11:43
  • @abarnert - I looked at those docs, and as far as I understand I need to use SimpleXMLElement to create the xml. But can I also use the original definition of `VerzoekTotInformatieRequest` to somehow build upon and only fill in the missing details? – kramer65 Apr 24 '15 at 11:53
  • 1
    The only one of those examples that uses SimpleXMLElement to create the whole XML is the very last one, "Raw example", which you only use when you need "-RAW full control- (manual serialization of parameters and desserialization of return values)". If you don't need that, don't follow that example. – abarnert Apr 24 '15 at 12:02
  • @abarnert - Ah, now I see, thank you! One last question; how do I show/inspect the xml that the client constructs. I now did for example `client['VerzoekTotInformatieRequest'] = {'berichtversie': 'lala'}`. How do I check how this influenced the xml it produces? – kramer65 Apr 24 '15 at 12:42

1 Answers1

6

Constructing xml is not the necessary (or correct) way to call a soap method. PySimpleSoap has already provided quite an elegant and human-readable way to do this:

client = SoapClient(wsdl='http://www1.kadaster.nl/1/schemas/kik-inzage/20141101/verzoekTotInformatie-2.1.wsdl', trace=True)
client.VerzoekTotInformatie(Aanvraag={'berichtversie':4.7, 
                                      'klantReferentie':'cum murmure', 
                                      'productAanduiding': 'aeoliam venit'})

The debug log would be like this:

INFO:pysimplesoap.client:POST https://service1.kadaster.nl/kik/inzage/20141101/VerzoekTotInformatieService
DEBUG:pysimplesoap.client:SOAPAction: "VerzoekTotInformatie"
Content-length: 842
Content-type: text/xml; charset="UTF-8"
DEBUG:pysimplesoap.client:<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soap:Header/>
        <soap:Body>
            <VerzoekTotInformatieRequest xmlns="http://www.kadaster.nl/schemas/kik-inzage/20141101">
                <Aanvraag xmlns="http://www.kadaster.nl/schemas/kik-inzage/ip-aanvraag/v20141101">
                    <berichtversie xmlns="http://www.kadaster.nl/schemas/kik-inzage/ip-aanvraag/v20141101">4.7000000000</berichtversie>
                    <klantReferentie xmlns="http://www.kadaster.nl/schemas/kik-inzage/ip-aanvraag/v20141101">cum murmure</klantReferentie>
                    <productAanduiding xmlns="http://www.kadaster.nl/schemas/kik-inzage/ip-aanvraag/v20141101">aeoliam venit</productAanduiding>
                </Aanvraag>
            </VerzoekTotInformatieRequest>
        </soap:Body>
</soap:Envelope>

As you can see, the xml is automatically constructed and sent to server. However I got 401: Unauthorized error, which you may know how to fix.

ljk321
  • 16,242
  • 7
  • 48
  • 60
  • Thanks! I didn't know I could simply use dictionaries to create objects in the xml. And I indeed know how to fix the 401; you need to pay for the service.. :-). Thanks a million! I'll award you the +100 once I can (in 20 minutes). – kramer65 Apr 28 '15 at 09:31
  • Hi @skyline75489. After the awesome help you gave me on my question here I'm now facing an issue with the returned xml creating a TypeError in pysimplesoap (`TypeError: Tag: IMKAD_Perceel invalid (type not found)`). I created a new question about that here: http://stackoverflow.com/questions/30258321/typeerror-in-soaprequest-using-pysimplesoap . Would you possibly know anything about how to fix that type error? – kramer65 May 15 '15 at 13:19