[Tutor] python webservice suds

贾晓磊 jiaxiaolei19871112 at gmail.com
Tue Nov 29 15:28:42 CET 2011


hi, all:

is someone familiar to suds.

I'm making a webservice client, and meet some problems.
I try to ask helps from soap at python.org, lists at libertylost.org,
python-tornado at googlegroups.com, while, the problem still exist.


part 1: how do you think the xml in the url:

"http://211.137.45.104:9006/LnXxtCpInterface/services/LNXxtSyncService?wsdl"

<complexType name="ArrayOf_soapenc_string">
<complexContent>
<restriction base="soapenc:Array">
<attribute ref="soapenc:arrayType" wsdl:arrayType="xsd:string[]"/>
</restriction>
</complexContent>
</complexType>

part 2: in fact, the server is made by Axis, which is a web service
framework in Java.
Before i develop the client, there already have a java client for the
server.
the code  are below:

if (temp.length % MTINFO_LENGTH != 0) {
String[] remainBlock = new String[temp.length - jMark];
 for (int i = 0; i < remainBlock.length; i++) {
remainBlock[i] = temp[jMark];
 jMark++;
}

mark = lnxss.sendMt(remainBlock);

After read the code,  we know that the the inparams of sendMt is String[].
In fact, the purpose of senMt() is to send some shotmessage to a mobile
phone. you can find remobile in the parameters.

part 3: Besides, the server has some check, which i have add it in the
newest code.

servicecode: PABB4BEIJING
passwd: QWERTPABB
namespace: service.global.v1_0.wsdl.protocol.xxt (you can see it in the url)

I have tried  to add the service code and passwd in the code.
 while,  what  still puzzled me is that in suds, how to add the namespace
to the client.
how to use the ArrayOf_soapen_string is a problem. in my code, i provide a
list which contains some string. in my view, i should provide a object like
your code,
aoss = client.factory.create('ArrayOf_soapen_string')
then, what should i do next?  how to assign a value for the parameter of
aoss?

part 4:
# the newest code :

import suds
def test_sms4():
    import logging
    logging.basicConfig(level=logging.ERROR)
    url = "
http://211.137.45.104:9006/LnXxtCpInterface/services/LNXxtSyncService?wsdl"
    from suds.transport.https import HttpAuthenticated
    credentials = dict(username='PABB4BEIJING', password='QWERTPABB')
    t = HttpAuthenticated(**credentials)
    client =
suds.client.Client(url,transport=t,cache=None,xstq=False,faults=False)
    #client = suds.client.Client(url,cache=None,xstq=False)
    aoss = client.factory.create('ArrayOf_soapenc_string')
    #client.set_options(namespace='service.global.v1_0.wsdl.protocol.xxt')
    print 'client', client
    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]

    #client.service.sendMt(aoss)
    output = client.service.sendMt(mtinfo=req)
    print 'output', output



# output:

w_jiaxiaolei at drone-009:~/tornadows-0.9.1/demos$ python suds_client.py
client
Suds ( https://fedorahosted.org/suds/ )  version: 0.3.7 GA  build:
R580-20091016

Service ( LNXxtSyncServiceService )
tns="service.global.v1_0.wsdl.protocol.xxt"
   Prefixes (3)
      ns0 = "http://common.v1_0.obj.protocol.xxt"
      ns1 = "http://schemas.xmlsoap.org/soap/encoding/"
      ns2 = "service.global.v1_0.wsdl.protocol.xxt"
   Ports (1):
      (LNXxtSyncService)
         Methods (5):
            sendMo(ArrayOf_soapenc_string moInfo, )
            sendMt(ArrayOf_soapenc_string mtInfo, )
            syncCorp(ArrayOf_tns2_GroupOrderInfo orderInfo, )
            syncResponseRpt(ArrayOf_soapenc_string rpt, )
            syncStaff(ArrayOf_tns2_UserOrderInfo orderInfo, )
         Types (54):
            ns1:Array
            ArrayOf_soapenc_string
            ArrayOf_tns2_GroupOrderInfo
            ArrayOf_tns2_UserOrderInfo
            ...

ERROR:suds.client:<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns0="service.global.v1_0.wsdl.protocol.xxt"
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/>
   <SOAP-ENV:Body>
      <ns0:sendMt>
         <mtInfo xsi:type="ArrayOf_soapenc_string"/>
      </ns0:sendMt>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
output (500, (detail){
   fault =
      (fault){
         _href = "#id0"
      }
   exceptionName = "xxt.protocol.obj.v1_0.common.ServiceException"
   hostname = "ln_xxt_mh01"
 })


-- jiaxiaolei







2011/11/29 xin zou <joy2everyone.z at gmail.com>

> Sorry that I used many "should" as my subjective judgment, you can try to
> test with the closed correct args of "*array_soapenc_str*" refer the
> related document.
>
> Thanks,
> Xin
>
> 在 2011年11月29日 下午8:20,xin zou <joy2everyone.z at gmail.com>写道:
>
> Hi,
>>
>> Here are my testing code with your supplied service:
>>
>> ===============================================================
>> from suds.client import Client
>> import logging
>>
>> #logging.basicConfig(level=logging.DEBUG)
>>
>> url = '
>> http://211.137.45.104:9006/LnXxtCpInterface/services/LNXxtSyncService?wsdl
>> '
>> client = Client(url)
>>
>> array_soapenc_str = client.factory.create('ArrayOf_soapenc_string')
>> array_soapenc_str._arrayType = 'test'
>> array_soapenc_str._offset = '1'
>> array_soapenc_str._id = '1'
>> array_soapenc_str._href = "http://www.test.com"
>> array_soapenc_str._arrayType = 'test2'
>>
>> print client.service.sendMt(array_soapenc_str)
>>
>> ===============================================================
>>
>> My occurred error was " WebFault: Server raised fault: '' "(you can
>> remove the DEBUG comment for more information), I think it should be my
>> testing args were incorrect. You should be familiar with these request
>> args, as well as you should have the corresponding document of this web
>> service (e.g. what is the purpose of the "sendMt" operation), right? Hope
>> these are helpful for you. Good luck!
>>
>> BTW, the more detailed document of the released web service, the better
>> for the client :)
>>
>> Thanks,
>> Xin
>>
>>
>>
>>
>> 2011/11/29 贾晓磊 <jiaxiaolei19871112 at gmail.com>
>>
>>> Hi, all:
>>>
>>> First of all, I will admire I am a novice to web service. I read
>>> someting about webservie about tornado webservice and find thant nearly all
>>> the client is developed by suds.
>>>
>>> What I need now is to invoke a method  sendMt provided by the web
>>> service server(prehaps the server is made by java language using a framwork
>>> named Axis).
>>>
>>> I try to invoke the sendMt method provided by the server, then failded.
>>> There are the tests as follows:
>>>
>>> you can see the whole wsdl file in "
>>> http://211.137.45.104:9006/LnXxtCpInterface/services/LNXxtSyncService?wsdl",
>>> or read in  the attachment(when i use suds, in /tmp/suds/* i find them) .
>>>
>>> method 1:
>>>
>>> import suds
>>>
>>> def test_sms():
>>>     #TODO: it's failed
>>>     url = "
>>> http://211.137.45.104:9006/LnXxtCpInterface/services/LNXxtSyncService?wsdl
>>> "
>>>     #client = suds.client.Client(url,faults=False)
>>>     client = suds.client.Client(url)
>>>     print 'client', client
>>>     a = ['jia','xiao']
>>>     output = client.service.sendMt(a)
>>>     print 'output', output
>>>
>>>
>>> # the output:
>>>
>>> client
>>> Suds ( https://fedorahosted.org/suds/ )  version: 0.3.7 GA  build:
>>> R580-20091016
>>>
>>> Service ( LNXxtSyncServiceService )
>>> tns="service.global.v1_0.wsdl.protocol.xxt"
>>>    Prefixes (3)
>>>       ns0 = "http://common.v1_0.obj.protocol.xxt"
>>>       ns1 = "http://schemas.xmlsoap.org/soap/encoding/"
>>>       ns2 = "service.global.v1_0.wsdl.protocol.xxt"
>>>    Ports (1):
>>>       (LNXxtSyncService)
>>>          Methods (5):
>>>             sendMo(ArrayOf_soapenc_string moInfo, )
>>>             sendMt(ArrayOf_soapenc_string mtInfo, )
>>>             syncCorp(ArrayOf_tns2_GroupOrderInfo orderInfo, )
>>>             syncResponseRpt(ArrayOf_soapenc_string rpt, )
>>>             syncStaff(ArrayOf_tns2_UserOrderInfo orderInfo, )
>>>          Types (54):
>>>             ns1:Array
>>>             ArrayOf_soapenc_string
>>>             ArrayOf_tns2_GroupOrderInfo
>>>             ArrayOf_tns2_UserOrderInfo
>>>             ns1:ENTITIES
>>>             ns1:ENTITY
>>>             ...
>>> No handlers could be found for logger "suds.client"
>>> Traceback (most recent call last):
>>>   File "suds_client.py", line 124, in <module>
>>>     test_sms2()
>>>   File "suds_client.py", line 99, in test_sms2
>>>     output = client.service.sendMt(a)
>>>   File
>>> "/usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/client.py",
>>> line 535,
>>>
>>> in __call__
>>>     return client.invoke(args, kwargs)
>>>   File
>>> "/usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/client.py",
>>> line 595,
>>>
>>> in invoke
>>>     result = self.send(msg)
>>>   File
>>> "/usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/client.py",
>>> line 630,
>>>
>>> in send
>>>     result = self.failed(binding, e)
>>>   File
>>> "/usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/client.py",
>>> line 681,
>>>
>>> in failed
>>>     r, p = binding.get_fault(reply)
>>>   File
>>> "/usr/local/lib/python2.6/dist-packages/suds-0.3.7-py2.6.egg/suds/bindings/binding.py",
>>>
>>> line 235, in get_fault
>>>     raise WebFault(p, faultroot)
>>> suds.WebFault: Server raised fault: 'No such operation 'sendMt''
>>>
>>>
>>> #Note:
>>> 1: the url "
>>> http://211.137.45.104:9006/LnXxtCpInterface/services/LNXxtSyncService?wsdl"
>>> is
>>>
>>> develped in Internet, anyone can use it.
>>> 2: in my view, the server is made by java Axis, and the inparams of
>>> sendmt is
>>>
>>> ArrayOf_soapenc_string(In java, it means a array of String, in python,
>>> it means a list whose
>>>
>>> items are string).
>>> 3: the problem has puzzled me for nearly a week, please someone can give
>>> me some points.
>>>
>>>
>>> # besides the suds, i try other methods as follows, whlie, still failed.
>>>
>>> method 2:
>>>
>>> from SOAPpy import SOAPProxy
>>> def test_sms():
>>>     """test for ln sms java webservice
>>>     """
>>>     #TODO:invoke sms is stil failed
>>>     url = "
>>> http://211.137.45.104:9006/LnXxtCpInterface/services/LNXxtSyncService"
>>>     server = SOAPProxy(url)
>>>     args = ['jia','xiao']
>>>     print server.sendMt(args)
>>>
>>>
>>> # output:
>>> w_jiaxiaolei at drone-009:~/tornadows-0.9.1/demos$ python  soappy_client.py
>>> Traceback (most recent call last):
>>>   File "soappy_client.py", line 59, in <module>
>>>     test_sms()
>>>   File "soappy_client.py", line 31, in test_sms
>>>     print server.sendMt(args)
>>>   File "/usr/lib/pymodules/python2.6/SOAPpy/Client.py", line 470, in
>>> __call__
>>>     return self.__r_call(*args, **kw)
>>>   File "/usr/lib/pymodules/python2.6/SOAPpy/Client.py", line 492, in
>>> __r_call
>>>     self.__hd, self.__ma)
>>>   File "/usr/lib/pymodules/python2.6/SOAPpy/Client.py", line 406, in
>>> __call
>>>     raise p
>>> SOAPpy.Types.faultType: <Fault soapenv:Server.generalException: :
>>> <SOAPpy.Types.structType
>>>
>>> detail at 26709888>: {'fault': <SOAPpy.Types.structType multiRef at
>>> 26707800>: {'text':
>>>
>>> 'SoapHeader is null', 'messageId': 'SEV_0003'}, 'exceptionName':
>>>
>>> 'xxt.protocol.obj.v1_0.common.ServiceException', 'hostname':
>>> 'ln_xxt_mh01'}>
>>>
>>>
>>> method 3:
>>>
>>> from SOAPpy import WSDL
>>>
>>> def test_sms():
>>>     """for sms
>>>     """
>>>      url = "
>>> http://211.137.45.104:9006/LnXxtCpInterface/services/LNXxtSyncService?wsdl
>>> "
>>>     server = WSDL.Proxy(url)
>>>     #print 'methods:',server.methods.keys()
>>>     #print 'input type:',server.methods['sendMt'].inparams[0].type
>>>     #print 'input name:',server.methods['sendMt'].inparams[0].name
>>>     #print 'output type:',server.methods['sendMt'].outparams[0].type
>>>     #print 'output name:',server.methods['sendMt'].outparams[0].name
>>>     a = ['jia','xiao']
>>>     results=server.sendMt(a)
>>>     print results
>>>
>>> # output:
>>> w_jiaxiaolei at drone-009:~/tornadows-0.9.1/demos$ python  wsdl_client.py
>>> /usr/lib/pymodules/python2.6/SOAPpy/wstools/XMLSchema.py:2871:
>>> DeprecationWarning:
>>>
>>> object.__init__() takes no parameters
>>>   tuple.__init__(self, args)
>>> Traceback (most recent call last):
>>>   File "wsdl_client.py", line 48, in <module>
>>>     test_sms()
>>>   File "wsdl_client.py", line 41, in test_sms
>>>     results=server.sendMt(a)
>>>   File "/usr/lib/pymodules/python2.6/SOAPpy/Client.py", line 470, in
>>> __call__
>>>     return self.__r_call(*args, **kw)
>>>   File "/usr/lib/pymodules/python2.6/SOAPpy/Client.py", line 492, in
>>> __r_call
>>>     self.__hd, self.__ma)
>>>   File "/usr/lib/pymodules/python2.6/SOAPpy/Client.py", line 406, in
>>> __call
>>>     raise p
>>> SOAPpy.Types.faultType: <Fault soapenv:Server.generalException: :
>>> <SOAPpy.Types.structType
>>>
>>> detail at 31753352>: {'fault': <SOAPpy.Types.structType multiRef at
>>> 31753280>: {'text':
>>>
>>> 'SoapHeader is null', 'messageId': 'SEV_0003'}, 'exceptionName':
>>>
>>> 'xxt.protocol.obj.v1_0.common.ServiceException', 'hostname':
>>> 'ln_xxt_mh01'}>
>>>
>>
>>
>


-- 
NAME: 贾晓磊/Jia Xiaolei
MOBILE: 13011292217
QQ: 281304051
MICRO-BLOG:  http://weibo.com/2183890715
GMAIL: jiaxiaolei19871112 at gmail.com <gmail%3Ajiaxiaolei19871112 at gmail.com>




-- 
NAME: 贾晓磊/Jia Xiaolei
MOBILE: 13011292217
QQ: 281304051
MICRO-BLOG:  http://weibo.com/2183890715
GMAIL: jiaxiaolei19871112 at gmail.com <gmail%3Ajiaxiaolei19871112 at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111129/e5b8fe03/attachment-0001.html>


More information about the Tutor mailing list