如何反省SOAP数据类型?

时间:2015-04-24 08:31:56

标签: python soap soap-client soappy pysimplesoap

之前从未使用过SOAP,我现在正试图关注this tutorial以了解荷兰政府土地登记册(kadaster.nl)的SOAP服务:

>>> 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')

所以我现在明白我需要使用VerzoekTotInformatie类型的消息调用方法VerzoekTotInformatieRequest(转换为RequestForInformation)。

但是从这里我有点失落。我如何构建这样的VerzoekTotInformatieRequest?我怎样才能进一步反思这个VerzoekTotInformatieRequest

非常感谢有关如何从这里开始的任何提示。

PS。如果我应该使用另一个库(但我更喜欢Python),那也没关系。我读了关于suds的好东西,但由于那没有提交for over 3 years,我认为它是遗弃软件。我也尝试了pysimplesoap,这似乎很好,但我不知道如何使用它来反省SOAP服务。

1 个答案:

答案 0 :(得分:3)

你对这一点的观察是正确的。但我首先使用SOAP客户端工具探索WSDL,以掌握其结构和引用。查看WSDL时,请注意在名为.xsd的引用verzoekTotInformatie-2.1.xsd模式中如何定义类型。然后,此架构引用并包含其他20个架构文件:

High-res image - click here.

enter image description here

显然,在你的情况下,通过阅读自己来追随一切变成了一场噩梦(无论如何,WSDL都不是为了人类阅读而设计的,但是你的非常非常嵌套)。

所以我建议你在SOAP UI中导入这个WSDL(它是免费的,这是我在上面的截图中使用的)并使用WSDL url创建一个新项目:

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

它将导入eveything并为您创建示例请求。对我来说,它甚至试图根据字段的类型添加一些lorem-ipsum样本数据:

<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>

导入所有内容后,您可以展开项目,然后右键单击绑定VezorekToInformatieBinding并选择Show Interface Viewer以探索您需要进一步内省的任何类型(包括请求)引用的模式。

随着你的整个定义,你可以更容易地进行反省。在您的情况下,必须有一个选项来导入WSDL和&#34;展开&#34;所有的包含/引用首先,只有当你有完整的图片时才开始反省。如果没有这样的选项,您可能必须遵循引用并逐个包含。

希望这有助于作为一个起点。祝你好运!