Search code examples
pythonsoapwsdlspyne

Spyne - how to duplicate one elements of wsdl file created by spyne?


I need to duplicate one of the elements of generated wsdl file. My code is like this:

class SDPSimulator(ServiceBase):
@rpc(UserCredential, Unicode, Unicode, Unicode, Integer,
     _returns=SendSmsReturn.customize(sub_name='return'))
def sendSms(ctx, userCredential, srcAddress, regionIds,msgBody,maxSendCount): 

I want to create my request wsdl file like this with Spyne:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:loc="localhost" xmlns:apps="apps.simulator.views">
   <soapenv:Header/>
   <soapenv:Body>
      <loc:sendSms>
         <!--Optional:-->
         <loc:userCredential>
            <!--Optional:-->
            <apps:password>test</apps:password>
            <!--Optional:-->
            <apps:username>test</apps:username>
         </loc:userCredential>
         <!--Optional:-->
         <loc:srcAddress>982156898</loc:srcAddress>
         <!--Optional:-->
         <loc:regionIds>77</loc:regionIds>
         <loc:regionIds>78</loc:regionIds>
         <loc:regionIds>79</loc:regionIds>
         <!--Optional:-->
         <loc:msgBody>Hi there</loc:msgBody>
         <!--Optional:-->
         <loc:maxSendCount>12</loc:maxSendCount>
      </loc:sendSms>
   </soapenv:Body>
</soapenv:Envelope>

How can I write my code to duplicate regionIds in wsdl file and send a request like above?


Solution

  • I finally find it :) To do so I have to write my code like this:

    class SDPSimulator(ServiceBase):
        @rpc(UserCredential, Unicode, Unicode.customize(max_occurs='unbounded'), Unicode, Integer,
             _returns=SendSmsReturn.customize(sub_name='return'))
        def sendSms(ctx, userCredential, srcAddress, regionIds, msgBody, maxSendCount):
    

    With this part of code: Unicode.customize(max_occurs=50) I can specify how many times <regionIds></regionIds> could be duplicated.