Search code examples
pythonsoapsoap-clientsoappypysimplesoap

How to introspect into SOAP data types?


Having never worked with SOAP before, I'm now trying to follow this tutorial to find out about the SOAP service of the Dutch government land register (kadaster.nl):

>>> from SOAPpy import WSDL
>>> server = WSDL.Proxy('http://www1.kadaster.nl/1/schemas/kik-inzage/20141101/verzoekTotInformatie-2.1.wsdl')
/Library/Python/2.7/site-packages/wstools/XMLSchema.py:1280: UserWarning: annotation is ignored
  warnings.warn('annotation is ignored')
/Library/Python/2.7/site-packages/wstools/XMLSchema.py:1217: UserWarning: Not keeping schema component.
  warnings.warn("Not keeping schema component.")
>>> server.methods.keys()
[u'VerzoekTotInformatie']
>>> callInfo = server.methods['VerzoekTotInformatie']
>>> callInfo.inparams[0].name
u'body'
>>> callInfo.inparams[0].type
(u'http://www.kadaster.nl/schemas/kik-inzage/20141101', u'VerzoekTotInformatieRequest')

So I now understand I need to call the method VerzoekTotInformatie (which translates as RequestForInformation) with a message of type VerzoekTotInformatieRequest.

But from here I'm kinda lost. How do I construct such a VerzoekTotInformatieRequest? How can I further introspect into this VerzoekTotInformatieRequest?

Any tips on how to proceed from here would be greatly appreciated.

ps. If I should use another library (but I prefer Python) that is also okay. I read good things about suds, but since that didn't have a commit for over 3 years I considered it abandonware. I also tried pysimplesoap, which seems good, but I didn't know how to use it to introspect into the SOAP service.


Solution

  • Your observations to this point are right. But I'd first explore the WSDL with a SOAP client tool to get a grasp on its structure and references. When you look at the WSDL, notice how the types are defined in a referenced .xsd schema named verzoekTotInformatie-2.1.xsd. Then this schema is referencing and including 20 other schema files:

    High-res image - click here.

    enter image description here

    Obviously in your case it becomes a nightmare to follow everything by just reading yourself (WSDL is not indended for human reading by design anyway, but yours is very, very nested).

    So I suggest you import this WSDL in SOAP UI (it is free, this is what I used in the screenshot above) and create a new project using the WSDL url:

    http://www1.kadaster.nl/1/schemas/kik-inzage/20141101/verzoekTotInformatie-2.1.wsdl

    It will import eveything and create a sample request for you. For me it even tried to add some lorem-ipsum sample data, based on the types of the fields:

    <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>4.7</v20:berichtversie>
                <v20:klantReferentie>cum murmure</v20:klantReferentie>
                <v20:productAanduiding>aeoliam venit</v20:productAanduiding>
                <!--Optional:-->
                <v20:Gebruiker>
                   <v20:identificatie>ventos tempestatesqu</v20:identificatie>
                </v20:Gebruiker>
                <v20:Ingang>
                   <!--You have a CHOICE of the next 3 items at this level-->
                   <v20:Object>
                      <!--You have a CHOICE of the next 2 items at this level-->
                      <v20:IMKAD_OZLocatie>
                         <v20:adres>
                            <v20:BAG_NummerAanduiding>
                               <v20:postcode>temper</v20:postcode>
                               <v20:huisnummer>turbine corripuit</v20:huisnummer>
                               <!--Optional:-->
                               <v20:huisletter>r</v20:huisletter>
                               <!--Optional:-->
                               <v20:huisnummertoevoeging>frem</v20:huisnummertoevoeging>
                            </v20:BAG_NummerAanduiding>
                         </v20:adres>
                         <!--Optional:-->
                         <v20:bijOfTegenover>ferant rapidi</v20:bijOfTegenover>
                      </v20:IMKAD_OZLocatie>
                      <v20:IMKAD_KadastraleAanduiding>
                         <!--Optional:-->
                         <v20:gemeente>sceptra tenens</v20:gemeente>
                         <v20:sectie>turbine corripuit scopuloque</v20:sectie>
                         <v20:perceelnummer>flamm</v20:perceelnummer>
                         <!--Optional:-->
                         <v20:appartementsindex>prof</v20:appartementsindex>
                         <!--Optional:-->
                         <v20:deelperceelnummer>nubi</v20:deelperceelnummer>
                         <!--Optional:-->
                         <v20:AKRKadastraleGemeenteCode>ac vi</v20:AKRKadastraleGemeenteCode>
                      </v20:IMKAD_KadastraleAanduiding>
                   </v20:Object>
                   <v20:PersoonsIngang>
                      <v20:Persoon>
                         <!--You have a CHOICE of the next 4 items at this level-->
                         <v20:BSN>100</v20:BSN>
                         <!--Optional:-->
                         <v20:KVKNummer>rapidum</v20:KVKNummer>
                         <!--Optional:-->
                         <v20:RSIN>caelumque</v20:RSIN>
                         <v20:kadastraleIdentificatie>100</v20:kadastraleIdentificatie>
                      </v20:Persoon>
                      <!--Optional:-->
                      <v20:Restrictie>
                         <v20:maximumAantalObjecten>100</v20:maximumAantalObjecten>
                      </v20:Restrictie>
                   </v20:PersoonsIngang>
                   <v20:Brondocument>
                      <v20:IMKAD_DeelEnNummer>
                         <v20:deel>circu</v20:deel>
                         <v20:nummer>coniu</v20:nummer>
                         <!--Optional:-->
                         <v20:reeks>arce sceptra</v20:reeks>
                         <v20:ipa_registerCodeSub>circum claustra fremunt</v20:ipa_registerCodeSub>
                      </v20:IMKAD_DeelEnNummer>
                   </v20:Brondocument>
                </v20:Ingang>
             </v20:Aanvraag>
          </ns:VerzoekTotInformatieRequest>
       </soapenv:Body>
    </soapenv:Envelope>
    

    After everything is imported you can expand the project and then right-click on the binding VezorekToInformatieBinding and select Show Interface Viewer to explore any types (including the request) you need to further introspect that are defined in the referenced schemas.

    With the whole definition at your disposal it will be much easier to do an introspection. In your case, there must be an option to import the WSDL and "expand" all the includes/references first and only then begin introspecting, when you have the whole picture available. If there is no such option, you might have to follow the references and includes one by one.

    Hope this helps as a starting point. Good luck!