1

In one of my application am consuming SUDS WSDL(SOAP) web services at GAE python.

My Py Code:

url = 'http://203.215.51.43/Gateway/Execute?WSDL'
client = Client(url)
print client

So it printing at server console

Suds ( https://fedorahosted.org/suds/ )  version: 0.4 GA  build: R699-20100913
Service ( GatewayService ) tns="urn:fks:jcaps:gateway"
   Prefixes (2)
      ns0 = "http://fks.com/gtwy"
      ns1 = "urn:fks:jcaps:gateway:JavaException"
   Ports (1):
      (Execute)
         Methods (1):
            redeem(xs:string SessionId, xs:string TerminalId, xs:string StoreCod
e, xs:string CashMemoNo, xs:string CashMemoDate, xs:double InvoiceAmount, xs:str
ing TimeStamp, xs:string CashierId, xs:string MerchantId, ns0:SPCReqDtls SPCReqD
tls, ns0:VoucherReqDtls[] VoucherReqDtls, ns0:CardReqDtls CardReqDtls, )
         Types (1):
            ns1:JavaExceptionType

Actually am able pass string, double type values in redeem method but not an array/list type,

result = client.service.redeem(SessionId=result['SessionId'], StoreCode='4739', TerminalId='T1081', TimeStamp='01-01-2011 01:01:00.000')

But am not able to pass here VoucherReqDtls array

the WSDL's XML code of this VoucherReqDtls is as below,

    <!--Zero or more repetitions:-->
             <gtwy:VoucherReqDtls>
                <gtwy:VoucherType>GV</gtwy:VoucherType>
                <!--1 or more repetitions:-->
                <gtwy:VoucherReq>
                   <gtwy:VoucherNo>344234242</gtwy:VoucherNo>
                </gtwy:VoucherReq>
                <gtwy:VoucherReq>
                   <gtwy:VoucherNo>675685858</gtwy:VoucherNo>
                </gtwy:VoucherReq>
             </gtwy:VoucherReqDtls>

So how can i pass the VoucherReqDtls array/list in redeem method, here VoucherType is GV and count of VoucherNo could be more than one.

olly_uk
  • 11,559
  • 3
  • 39
  • 45
Niks Jain
  • 1,617
  • 5
  • 27
  • 53

1 Answers1

5

I think the issue is that the redeem method, if you visually inspect the WSDL, expects a complex type of GatwayReq which can be created with the following code :

>>> it = client.factory.create('ns0:GatewayReq')
>>> it
(GatewayReq){
   SessionId = None
   TerminalId = None
   StoreCode = None
   CashMemoNo = None
   CashMemoDate = None
   InvoiceAmount = None
   TimeStamp = None
   CashierId = None
   MerchantId = None
   SPCReqDtls = 
      (SPCReqDtls){
         SPCNo = None
         SPCAmt = None
      }
   VoucherReqDtls[] = <empty>
   CardReqDtls = 
      (CardReqDtls){
         CardType = None
         CardReq = 
            (CardReq){
               CardNo = None
               TransAmt = None
            }
      }
 }

you can add the elements to the GatewayReq object as you would anyt object attributes, i.e.

>>> it.SessionId = 'blahablhabalh'
>>> it
(GatewayReq){
   SessionId = "blahablhabalh"
   # the rest removed for readability

you would then call the redeem method like so :

>>>> client.service.redeem(it)

EDIT

you can create the required types using the below syntax :

entry1 = client.factory.create('ns0:GatewayReq.ns0:VoucherReqDtls')
>>> entry1
(VoucherReqDtls){
   VoucherType = None
   VoucherReq[] = <empty>
 }

This uses the mechanism to access none top level types as specified here suds docs - FACTORY

then you can add this to the main request object as below :

>>> entry1.VoucherType = 'GV'
>>> entry1.VoucherReq.append([12,34,56])
>>> entry1
(VoucherReqDtls){
   VoucherType = "GV"
   VoucherReq[] = 

      12,
      34,
      56,
 }
>>> entry1.VoucherReq.append(23)
>>> entry1
    (VoucherReqDtls){
       VoucherType = "GV"
       VoucherReq[] = 

      12,
      34,
      56,
      23,
 }

>>> it.VoucherReqDtls.append(entry1)
>>> it
(GatewayReq){
   SessionId = None
   TerminalId = None
   StoreCode = None
   CashMemoNo = None
   CashMemoDate = None
   InvoiceAmount = None
   TimeStamp = None
   CashierId = None
   MerchantId = None
   SPCReqDtls = 
      (SPCReqDtls){
         SPCNo = None
         SPCAmt = None
      }
   VoucherReqDtls[] = 
      (VoucherReqDtls){
         VoucherType = "GV"
         VoucherReq[] = 

            12,
            34,
            56,
            23,
  },
   CardReqDtls = 
      (CardReqDtls){
         CardType = None
         CardReq = 
            (CardReq){
               CardNo = None
               TransAmt = None
            }
      }
  }

this create xml as below which mathches the required syntax :

<SOAP-ENV:Header/>
   <ns0:Body>
      <ns1:GatewayReq>
         <ns1:SessionId>
            <ns1:SessionId/>
            <ns1:TerminalId/>
            <ns1:StoreCode/>
            <ns1:CashMemoNo/>
            <ns1:CashMemoDate/>
            <ns1:TimeStamp/>
            <ns1:CashierId/>
            <ns1:VoucherReqDtls>
               <ns1:VoucherType>GV</ns1:VoucherType>
               <ns1:VoucherReq>12</ns1:VoucherReq>
               <ns1:VoucherReq>34</ns1:VoucherReq>
               <ns1:VoucherReq>56</ns1:VoucherReq>
               <ns1:VoucherReq>23</ns1:VoucherReq>
            </ns1:VoucherReqDtls>
            <ns1:VoucherReqDtls>
               <ns1:VoucherType>GV</ns1:VoucherType>
               <ns1:VoucherReq>12</ns1:VoucherReq>
               <ns1:VoucherReq>34</ns1:VoucherReq>
               <ns1:VoucherReq>56</ns1:VoucherReq>
               <ns1:VoucherReq>23</ns1:VoucherReq>
            </ns1:VoucherReqDtls>
         </ns1:SessionId>
         <ns1:TerminalId/>
         <ns1:StoreCode/>
         <ns1:CashMemoNo/>
         <ns1:CashMemoDate/>
         <ns1:TimeStamp/>
         <ns1:CashierId/>
      </ns1:GatewayReq>
   </ns0:Body>
</SOAP-ENV:Envelope>

or at least that is how i think it should work

hope it helps

olly_uk
  • 11,559
  • 3
  • 39
  • 45
  • thanks buddy..its really working fine for string, double type. & but still am not able to build/design **VoucherReqDtls** list/array as per as xml expected(as shown in quest) itself. – Niks Jain Aug 08 '12 at 15:05
  • yeah does seem to have some types missing, maybe the WSDL is not correct in its decleration? i'll have a look using some soap tools and see what i can do – olly_uk Aug 08 '12 at 15:08
  • [this](http://203.215.51.43/Gateway/Execute?WSDL) is my WSDL service. & one thing,i had tested over SOAPUI also. its working fine there..am only worried about exact structure of **VoucherReqDtls** array at redeem method. – Niks Jain Aug 08 '12 at 15:12
  • ha, i was just trying it in SOAPui and as you say it works perfectly. maybe this is a bug in suds? – olly_uk Aug 08 '12 at 15:13
  • ohh..i see!!..in the mean while..could you show me the rough VoucherReqDtls array structure?, so that i could apply in my code. – Niks Jain Aug 08 '12 at 15:15
  • No problem buddy...OK..if we want to pass simple array then how could we pass that programatically? – Niks Jain Aug 08 '12 at 15:58
  • 1
    let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/15071/discussion-between-olly-uk-and-niks) – olly_uk Aug 08 '12 at 16:00
  • buddy..you are a life saviour....I got solution over here..its working great.. :) thanks a ton.. – Niks Jain Aug 09 '12 at 10:03