SUDS: Pass Array Parameter in Client.service Method : GAE Python


 
 
 
 
 
 
 
 

Favorites

 
Click on a group’s star icon to add it to your favorites
 
 
 
 
 
SUDS: Pass Array Parameter in Client.service Method : GAE Python
4 posts by 1 author
 
 
Niks via StackOverflow 
8/8/12
 

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.



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/11864785/suds-pass-array-parameter-in-client-service-method-gae-python
 
 
 
 
olly_uk via StackOverflow 
8/8/12
 

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"
   TerminalId = None
   StoreCode = None
   CashMemoNo = None
   CashMemoDate = None
   InvoiceAmount = None
   TimeStamp = None
   CashierId = None
   MerchantId = None
   # the rest removed for readability

you would then call the redeem method like so :

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

or at least that is how i think it should work

hope it helps



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/11864785/suds-pass-array-parameter-in-client-service-method-gae-python/11866793#11866793
 
 
 
 
olly_uk via StackOverflow 
8/9/12
 
- show quoted text -

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 - FACTORYentry

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
            }
      }
  }
- show quoted text -
 
 
 
 
olly_uk via StackOverflow 
8/9/12
 
- show quoted text -
>>> 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 :

- show quoted text -

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>
- show quoted text -
 
 
 
 
 
posted @ 2014-02-19 22:37  elephantofafric  阅读(225)  评论(0)    收藏  举报