python - 如何内省(introspection) SOAP 数据类型?

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

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

但从这里我有点迷失了。如何构造这样的 VerzoekTotInformatieRequest?我如何进一步反射(reflection)这个 VerzoekTotInformatieRequest

任何有关如何从这里继续进行的提示将不胜感激。

ps。如果我应该使用另一个库(但我更喜欢Python)也没关系。我读到了关于suds的好东西,但因为没有提交 for over 3 years我认为它是废弃软件。我也尝试过 pysimplesoap,看起来不错,但我不知道如何使用它来内省(introspection) SOAP 服务。

最佳答案

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

High-res image - click here.

enter image description here

显然,在您的情况下,仅通过阅读自己来跟踪所有内容就变成了一场噩梦(无论如何,WSDL 并不是为人类阅读而设计的,但您的内容非常非常嵌套)。

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

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

它将导入所有内容并为您创建一个示例请求。对我来说,它甚至尝试根据字段的类型添加一些 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>

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

掌握了整个定义后,进行内省(introspection)就会容易得多。在您的情况下,必须有一个选项来导入 WSDL 并首先“展开”所有包含/引用,然后只有在您掌握了整个情况后才开始内省(introspection)。如果没有这样的选项,您可能必须遵循引用文献并一一包含。

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

关于python - 如何内省(introspection) SOAP 数据类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29842434/

相关文章:

python - 迭代字典列表中的值 PYTHON

spring - 通过 junit 测试 SOAP 端点会抛出 SAXParseException (soapenv :Envelope)

python - 为什么python中列表的 "sum"会变平?

python - grep:写入错误:子进程的管道损坏

authentication - 使用 Spring Web 服务添加 Spring Security @Secured 注释会禁用 Web 服务端点

PHP SoapClient : SoapFault exception Could not connect to host

PHP SoapClient 和读取属性

Python string.join ( list ) 最后一个条目为 "and"

php - SoapClient 调用返回 500 Internal Server Error