加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

求教:Axis2 做webservice client 端时遇到的一个问题

发布时间:2020-12-17 01:07:54 所属栏目:安全 来源:网络整理
导读:大家好: ? 最近一直在做webservice 相关的东西。 webservice 的特性要是跨平台,跨语言。 我自己分别用 Java 和 Python 搭建了两套webservice(从某种意义上来讲,不仅是兴趣爱好,也是企业需求). 其中Java中使用Axis2框架,server 端和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:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="SMSService">
<wsdl:port binding="tns:SMSServiceBinding" name="SMSServicePort">
<soap:address location="http://127.0.1.1:8001/SMSService"/>
</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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读