Generate Sample SOAP Request and Response Templates Using Only Python. No Zeep, SOAPUI, or any other tool

三世轮回 提交于 2020-12-12 12:24:35

问题


I'm pretty new to python and brand new to web services. I recently started on a project that I'm very passionate about and which has been a wonderful learning opportunity. However I'm very stuck after weeks of research and could use some help.

What I'm trying to do is make my own WSDL interface that works similar to SOAPUI. My program will parse any Workday WSDL file for necessary information, return a sample request template, allow the user to edit that template, and finally submit the xml to the Workday server.

Right now my program allows a user to submit Get and Put requests with preexisting xml templates. What I don't understand is how the Request/Response templates are generated from the WSDL. I'm not interested in tools, I want to understand how they do it so I can make my own.

EXAMPLE

The "Workday WSDL File" linked above is called Resource Management. I would download that WSDL from the Workday server in order to access the associated operations. One such operation is called "Get_Purchase_Item_Request". I would then generate the sample xml request from this WSDL, and get something like the following as a result:

<bsvc:Get_Purchase_Items_Request xmlns:bsvc="urn:com.workday/bsvc" bsvc:version="string">
   <!--You have a CHOICE of the next 2 items at this level-->
   <!-- Optional: -->
   <bsvc:Request_References>
     <!-- 1 or more repetitions: -->
     <bsvc:Purchase_Item_Reference bsvc:Descriptor="string">
       <!-- Zero or more repetitions: -->
       <bsvc:ID bsvc:type="string">string</bsvc:ID>
     </bsvc:Purchase_Item_Reference>
   </bsvc:Request_References>
</bsvc:Get_Purchase_Items_Request>

What I've tried:

  1. I use python's ElementTree module to handle the XML in my current program. I've poured over the docs but cannot see a way to generate the samples without a deeper understanding of how it's done in existing systems
  2. I have located what I think generates templates inside the open source SOAPUI code, trying to understand how they do it. The problem here is I don't know Java enough to use their code. Besides, I want to continue on how I currently am using python.
  3. The Zeep module is often recommended for handling SOAP clients. I'm currently learning how to use it. However, again, because I don't understand how the templates are generated, I'm struggling to use Zeep to make it happen. Also again, I'd like to continue as I have been, using ElementTree and Python. Even if I could manage to make it happen with Zeep, I still wouldn't understand how the templates are generated.
  4. I have created classes in my python code that handle the various parts of the WSDL file. I don't understand how to combine the various parts into an XML template.

TLDR: How are XML Templates generated from WSDL files? How can I parse a WSDL containing multiple operations and generate an XML template for one, specifically?

来源:https://stackoverflow.com/questions/58110712/generate-sample-soap-request-and-response-templates-using-only-python-no-zeep

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!