weixin_42494913 2011-12-08 17:38
浏览 229
已采纳

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:types


xsd:sequence

/xsd:sequence
/xsd:complexType


/xsd:schema
/wsdl:types


/wsdl:message


/wsdl:message




/wsdl:operation
/wsdl:portType




wsdl:input

/wsdl:input
wsdl:output

/wsdl:output
/wsdl:operation
/wsdl:binding



/wsdl:port
/wsdl:service
/wsdl:definitions

part 3: Axis2 client

package client;

import javax.xml.namespace.QName;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;

public class client_for_python {

public static void main(String[] args) throws Exception {

    // step 1: 使用RPC方式调用WebService
    RPCServiceClient serviceClient = new RPCServiceClient();
    Options options = serviceClient.getOptions();
    // step 2: 指定调用WebService的URL
    // url for python
    String url2 = "http://172.16.2.46:8001/SMSService";
    EndpointReference targetEPR = new EndpointReference(url2);
    options.setTo(targetEPR);
    // step 3: 指定getGreeting方法的参数值
    // step 5-6: (similiar whit
    // it!)下面是调用getPrice方法的代码,这些代码与调用getGreeting方法的代码类似
    Class[] classes = new Class[] { int.class };
    QName opAddEntry = new QName(
            "http://172.16.2.46:8001/SMSService/getPrice");
    System.out.println(serviceClient.invokeBlocking(opAddEntry,
            new Object[] {1}, classes)[0]);
}

}

#NOTE: 没有任何输出:
控制台上的所有输出就是:
log4j:WARN No appenders could be found for logger (org.apache.axis2.context.AbstractContext).
log4j:WARN Please initialize the log4j system properly.
null

在python server 端也没有收到任何参数。

我个人分析,可能是 Axis2 端 url 的指向有问题,可以看了一部分API, 也做了一些尝试,还是不行。
Hope someone can give me some points.Thanks!
(The blog permit not to use GaoShao BanMang,hehe!)

-- Jia Xiaolei

  • 写回答

2条回答 默认 最新

  • khan7923 2011-12-09 14:10
    关注

    我不知道你代码怎么做的,但是我可以告诉你怎么去解决这个问题,
    最简单有效的方法就是抓包,
    1.先确认请求能到服务端。
    2.从服务端抓两种不同客户端的访问过来的SOAP包。
    把两个抓到的包做对比,看看有什么不一样。排查代码问题还是网络问题,还是什么名空间的问题。

    祝你好运!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码