2

You know how SOAPUI can generate a complete XML template for a SOAP web service? I want to do that, but using the Python module Zeep.

I'm following the first example from here. I'm also referencing the Zeep Documentation.

Note: the web service I'm using is a public facing Workday web service and has NO customer data. More information is here.

Here is my code:

wsdl = "https://community.workday.com/sites/default/files/file-hosting/productionapi/Resource_Management/v33.1/Resource_Management.wsdl"
client = Client(wsdl)

message = client.create_message(client.service, "Get_Purchase_Items")

tree = ET.ElementTree(message)

xml = tree.write('test.xml',pretty_print=True)

The problem: This doesn't create a full XML template like SOAPUI does.

Here is what my code creates:

<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
  <soap-env:Body>
    <ns0:Get_Purchase_Items_Request xmlns:ns0="urn:com.workday/bsvc"/>
  </soap-env:Body>
</soap-env:Envelope>

This is what SOAPUI creates (and what I'm looking for from zeep):

   <soapenv:Header>
      <bsvc:Workday_Common_Header>
         <!--Optional:-->
         <bsvc:Include_Reference_Descriptors_In_Response>?</bsvc:Include_Reference_Descriptors_In_Response>
      </bsvc:Workday_Common_Header>
   </soapenv:Header>
   <soapenv:Body>
      <bsvc:Get_Purchase_Items_Request bsvc:version="?">
         <!--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="?">
               <!--Zero or more repetitions:-->
               <bsvc:ID bsvc:type="?">?</bsvc:ID>
            </bsvc:Purchase_Item_Reference>
         </bsvc:Request_References>
         <!--Optional:-->
         <bsvc:Request_Criteria>
            <!--Zero or more repetitions:-->
            <bsvc:Supplier_Reference bsvc:Descriptor="?">
               <!--Zero or more repetitions:-->
               <bsvc:ID bsvc:type="?">?</bsvc:ID>
            </bsvc:Supplier_Reference>
            <!--Zero or more repetitions:-->
            <bsvc:Supplier_Contract_Reference bsvc:Descriptor="?">
               <!--Zero or more repetitions:-->
               <bsvc:ID bsvc:type="?">?</bsvc:ID>
            </bsvc:Supplier_Contract_Reference>
            <!--Optional:-->
            <bsvc:Return_All_Advanced_Pricing>?</bsvc:Return_All_Advanced_Pricing>
            <!--Optional:-->
            <bsvc:Return_Active_Advanced_Pricing>?</bsvc:Return_Active_Advanced_Pricing>
            <!--Optional:-->
            <bsvc:Exclude_Pricing_Calculated_by_Conversion_Factor>?</bsvc:Exclude_Pricing_Calculated_by_Conversion_Factor>
         </bsvc:Request_Criteria>
         <!--Optional:-->
         <bsvc:Response_Filter>
            <!--Optional:-->
            <bsvc:As_Of_Effective_Date>?</bsvc:As_Of_Effective_Date>
            <!--Optional:-->
            <bsvc:As_Of_Entry_DateTime>?</bsvc:As_Of_Entry_DateTime>
            <!--Optional:-->
            <bsvc:Page>?</bsvc:Page>
            <!--Optional:-->
            <bsvc:Count>?</bsvc:Count>
         </bsvc:Response_Filter>
         <!--Optional:-->
         <bsvc:Response_Group>
            <!--Optional:-->
            <bsvc:Include_Reference>?</bsvc:Include_Reference>
         </bsvc:Response_Group>
      </bsvc:Get_Purchase_Items_Request>
   </soapenv:Body>
</soapenv:Envelope>

Questions

  1. How can I generate the full template with Zeep?
  2. Is there a different function from create_message() that will do this?
  3. Is there another Python module that will do this?

I posted a similar question two months ago, but moved on after I found a workaround. However, I keep coming back to this because it's really bugging me. So if someone could help me out I'd really appreciate it!

ChaserAide
  • 111
  • 1
  • 7

1 Answers1

0

The problem here seems to be the third line where you are not passing any parameters to the create_message call.

If you refer to the documentation you will find XML elements like Request_References, Response_Filter etc. As you are not passing in any elements it is just generating an empty XML.

Here is a sample code that might work in your case(untested):

wsdl = "https://community.workday.com/sites/default/files/file-hosting/productionapi/Resource_Management/v33.1/Resource_Management.wsdl"
client = Client(wsdl)

effective_date = datetime.datetime.strptime('2020-10-01', '%Y-%m-%d')
entry_date = datetime.datetime.strptime('2020-12-01', '%Y-%m-%d')
get_purchase_response_filter_type = client.get_type('ns0:Response_Filter')
response_filter_element = get_purchase_response_filter_type(
                                  As_Of_Effective_Date=effective_date,
                                  As_Of_Entry_DateTime=entry_date 
)
message = client.create_message(client.service, "Get_Purchase_Items", Response_Filter=response_filter_element)
tree = ET.ElementTree(message)
xml = tree.write('test.xml',pretty_print=True)

If you need to pass any soap headers then create_message also accepts a _soapheader parameter.

Sankalp
  • 1,128
  • 4
  • 14
  • 31