Hi, Dave:

Thanks very much for your reply.

With your help, the code is okay now. Thanks

def test_sms10():
    #NOTE: method 2:
    #1: import a encode
    from suds.xsd.doctor import ImportDoctor, Import
    imp = Import('http://schemas.xmlsoap.org/soap/encoding/')
    d = ImportDoctor(imp)

    #1: set the logging
    import logging
    logging.basicConfig(level=logging.ERROR)

    # 3: construt client
    url = "http://211.137.45.104:9006/LnXxtCpInterface/services/LNXxtSyncService?wsdl"
    client = suds.client.Client(url,doctor=d,cache=None,xstq=False,faults=False)

    # step 4: create the header
    from suds.sax.element import Element
    from suds.sax.attribute import Attribute
    code = Element('serviceCode').setText('PABB4BEIJING')
    pwd = Element('servicePwd').setText('QWERTPABB')
    header_list = [code, pwd]
    # 1
    # use insert:  it's okay
    #reqsoapheader = Element('ReqSOAPHeader').insert(code)
    #reqsoapheader.insert(code)
    # use child:¡¡okay
    reqsoapheader = Element('ReqSOAPHeader')
    reqsoapheader.children=[code,pwd]

    reqsoap_attribute = Attribute('xmlns', "http://common.v1_0.obj.protocol.xxt")
    reqsoap_attribute2 = Attribute('actor', "http://schemas.xmlsoap.org/soap/actor/next")
    reqsoap_attribute3 = Attribute('mustUnderstand', "0")
    reqsoapheader.append(reqsoap_attribute)
    reqsoapheader.append(reqsoap_attribute2)
    reqsoapheader.append(reqsoap_attribute3)

    client.set_options(soapheaders=reqsoapheader)

    # setp 5: provide the parameters
    item1 = "{'msgid':'1234567890','bizcode':'15140237310','serviceId':'1234567','recomobile':'15110791945','sendtime':'1322573860','content':'hi, this is just a test. you can ignore it. --jiaxiaolei'}"
    item2 = "{'msgid':'1234567891','bizcode':'15140237310','serviceId':'1234567','recomobile':'15110791946','sendtime':'1322573870','content':'hi, this is just a test. you can ignore it. --jiaxiaolei'}"
    req = [item1, item2]
    aoss = client.factory.create('ArrayOf_soapenc_string')
    aoss.item = req
    print 'client', client
    output = client.service.sendMt(aoss)
    print 'SOAP Request:\n', client.last_sent(), '\n'
    print 'SOAP Response:\n', client.last_received(), '\n'
    print 'the return: \n', output, '\n'

# output:
SOAP Request:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns0="service.global.v1_0.wsdl.protocol.xxt" xmlns:ns1="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
   <SOAP-ENV:Header>
      <ReqSOAPHeader xmlns="http://common.v1_0.obj.protocol.xxt" actor="http://schemas.xmlsoap.org/soap/actor/next" mustUnderstand="0">
         <serviceCode>PABB4BEIJING</serviceCode>
         <servicePwd>QWERTPABB</servicePwd>
      </ReqSOAPHeader>
   </SOAP-ENV:Header>
   <SOAP-ENV:Body>
      <ns0:sendMt>
         <mtInfo xsi:type="ArrayOf_soapenc_string">
            <item xsi:type="ns1:string">{&apos;msgid&apos;:&apos;1234567890&apos;,&apos;bizcode&apos;:&apos;15140237310&apos;,&apos;serviceId&apos;:&apos;1234567&apos;,&apos;recomobile&apos;:&apos;15110791945&apos;,&apos;sendtime&apos;:&apos;1322573860&apos;,&apos;content&apos;:&apos;hi, this is just a test. you can ignore it. --jiaxiaolei&apos;}</item>
            <item xsi:type="ns1:string">{&apos;msgid&apos;:&apos;1234567891&apos;,&apos;bizcode&apos;:&apos;15140237310&apos;,&apos;serviceId&apos;:&apos;1234567&apos;,&apos;recomobile&apos;:&apos;15110791946&apos;,&apos;sendtime&apos;:&apos;1322573870&apos;,&apos;content&apos;:&apos;hi, this is just a test. you can ignore it. --jiaxiaolei&apos;}</item>
         </mtInfo>
      </ns0:sendMt>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

SOAP Response:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope>
   <soapenv:Body>
      <ns1:sendMtResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <sendMtReturn xsi:type="soapenc:string">1</sendMtReturn>
      </ns1:sendMtResponse>
   </soapenv:Body>
</soapenv:Envelope>

the return:
(200, 1)

In actual fact, "you just forgot to add the servicePwd element to the ReqSOAPHeader element."
, i had try to add pwd in the code as follows, but failed.

 code = Element('ReqSOAPHeader').insert(code)
 pwd = Element('ReqSOAPHeader').insert(pwd)
 reqsoapheaders  = [code, pwd]
 for seqsoapheader in  reqsoapheaders:
    reqsoap_attribute = Attribute('xmlns', "http://schemas.acme.eu/")
    reqsoapheader.append(reqsoap_attribute)
 client.set_options(soapheaders=reqsoapheaders)

Now, I certainly know why it's failed. I did not know the thing the method does in bottom layer. In fact, all the methods such as "insert, append" are modify the xml .

Thanks again!

-- Jia Xiaolei







On Fri, Dec 2, 2011 at 10:09 PM, Dave Bonner <dbonner@cogolabs.com> wrote:
Unless I'm misreading, you've almost got it.  In the chunk below, you just forgot to add the servicePwd element to the ReqSOAPHeader element.


On Fri, Dec 2, 2011 at 1:22 AM, ¼ÖÏþÀÚ <jiaxiaolei19871112@gmail.com> wrote:
>     from suds.sax.element import Element
>     from suds.sax.attribute import Attribute
>     code = Element('serviceCode').setText('PABB4BEIJING')
>     pwd = Element('servicePwd').setText('QWERTPABB')
>     reqsoapheader = Element('ReqSOAPHeader').insert(code)
       reqsoapheader.insert(pwd)
>     reqsoap_attribute = Attribute('xmlns', "http://schemas.acme.eu/")
>     reqsoapheader.append(reqsoap_attribute)
>     client.set_options(soapheaders=reqsoapheader)

It's probably a little cleaner to do it like this, though:

    code = Element('serviceCode').setText('PABB4BEIJING')
    pwd = Element('servicePwd').setText('QWERTPABB')
    reqsoapheader = Element('ReqSOAPHeader')
    reqsoapheader.children = [code, pwd]

--
david bonner // dbonner@cogolabs.com




--
NAME: ¼ÖÏþÀÚ/Jia Xiaolei
MOBILE: 13011292217
QQ:¡¡281304051
MICRO-BLOG:  http://weibo.com/2183890715
GMAIL: jiaxiaolei19871112@gmail.com