日期:2014-05-17  浏览次数:20726 次

请教:Axis2 做webservice client 端时遇到的一个问题
大家好:

最近一直在做webservice 相关的东西。 webservice 的特性要是跨平台,跨语言。 我自己分别用 Java 和 Python 搭建了两套webservice(从某种意义上来讲,不仅是兴趣爱好,也是企业需求). 其中Java中使用Axis2框架,server 端和client端可以正常交互。 Python 中,server 端使用的是 tornadows(tornadow webservice), 客户端使用的是 suds, server 端和client端也可以正常交互。

既然webservice 是跨平台的,我用python client 端来访问 Axis2 serve端,最早有一些 encoding 的问题,最后也解决了。
现在我用 Axis2 client 访问我的 python server 端,一直不成功。 Axis2 client 收到的结果为null, python server端没有收到Axis2 client 的请求。 同样的python server, 我用python client(suds) 是可以的。

现在我把我的 python server 端的code, 在浏览器中访问得到的wsdl 文件,以及 Axis2 client的code 一起贴上来。 希望高手轻移尊步,帮我指点迷津。

part1: python server
#NOTE: 功能很简单,就是提供一个getPrice() 方法,接受一个整数,返回一个整数

import logging

import tornado.httpserver
import tornado.ioloop
import tornado.web
from tornadows import soaphandler
from tornadows import webservices
from tornadows import xmltypes
from tornadows.soaphandler import webservice
from tornado.options import define, options

define('mode', default='deploy')
define('port', type=int, default=8001)
options['logging'].set('warning')


class SMSService(soaphandler.SoapHandler):

  @webservice(_params=xmltypes.Integer,_returns=xmltypes.Integer)
  def getPrice(self,a):
  print 'come here'
  return 1987


if __name__ == '__main__':
  service = [('SMSService',SMSService)]
  app = webservices.WebService(service)
  ws = tornado.httpserver.HTTPServer(app)

  ws.listen(options.port)
  logging.warn("SMSService running on: localhost:%d", options.port)
  tornado.ioloop.IOLoop.instance().start()

part 2: wsdl 
#NOTE: 在浏览器中输入 ”http://172.16.2.46:8001/SMSService?wsdl“ 得到wsdl 文件如下:

<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://127.0.1.1:8001/SMSService/getPrice" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="SMSService" targetNamespace="http://127.0.1.1:8001/SMSService/getPrice">
<wsdl:types>
<xsd:schema targetNamespace="http://127.0.1.1:8001/SMSService/getPrice">
<xsd:complexType name="paramsTypes">
<xsd:sequence>
<xsd:element name="a" type="xsd:integer"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="params" type="tns:paramsTypes"/>
<xsd:element name="returns" type="xsd:integer"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="SMSServiceRequest">
<wsdl:part element="tns:params" name="parameters"/>
</wsdl:message>
<wsdl:message name="SMSServiceResponse">
<wsdl:part element="tns:returns" name="parameters"/>
</wsdl:message>
<wsdl:portType name="SMSServicePortType">
<wsdl:operation name="getPrice">
<wsdl:input message="tns:SMSServiceRequest"/>
<wsdl:output message="tns:SMSServiceResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="SMSServiceBinding" type="tns:SMSServicePortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="getPrice">
<soap:operation soapAction="http://127.0.1.1:8001/SMSService" style="document"/>
<wsdl:input>
<soap: