python webservice: from SOAPpy import WSDL
我在用SOAPpy.WSDL 时也遇到了这个问题,希望高手路过时指点一下:
>>> from SOAPpy import WSDL
>>> url = "http://211.137.45.104:9006/LnXxtCpInterface/services/LNXxtSyncService?wsdl"
>>> server = WSDL.Proxy(url)
/usr/lib/pymodules/python2.6/SOAPpy/wstools/XMLSchema.py:2871: DeprecationWarning: object.__init__() takes no parameters
tuple.__init__(self, args)
>>> server = WSDL.Proxy(url)
>>> server.methods.keys()
[u'sendMo', u'syncResponseRpt', u'sendMt', u'syncStaff', u'syncCorp']
>>> server.methods['sendMt']
<SOAPpy.wstools.WSDLTools.SOAPCallInfo instance at 0xeb9ab8>
>>> server.methods['sendMt'].inparams
[<SOAPpy.wstools.WSDLTools.ParameterInfo instance at 0xeb9b00>]
>>> server.methods['sendMt'].inparams[0].type
(u'service.global.v1_0.wsdl.protocol.xxt', u'ArrayOf_soapenc_string')
>>> server.methods['sendMt'].inparams[0].name
u'mtInfo'
>>> server.methods['sendMt'].outparams[0].name
u'sendMtReturn'
>>> server.methods['sendMt'].outparams[0].type
(u'http://schemas.xmlsoap.org/soap/encoding/', u'string')
>>> server.sendMt(['a','b'])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
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 13700416>: {'fault': <SOAPpy.Types.structType multiRef at 13700272>: {'text': 'SoapHeader is null', 'messageId': 'SEV_0003'}, 'exceptionName': 'xxt.protocol.obj.v1_0.common.ServiceException', 'hostname': 'ln_xxt_mh01'}>
#NOTE:
我这里只是调用了一下 sendMt() 方法,输入参数在java 中 其实就是一个 String[] , 为什么在 这里会出现这样的错误?
[解决办法]
为什么没人回复??
[解决办法]
几天过去了,还是没人回复; 给国外的一些论坛里发了一些,也没有完全解决; 这里将问题再描述一遍:
Hi, all:
First of all, I will admire I am a novice to web service.
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:
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@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@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'}>
-- jiaxiaolei
[解决办法]
呵呵,也许我的提问不应该放在这个地方,又或许是别的一些原因。。
现在python client --> java server 的问题基本解决了。
实现的方式是 suds.