大家好:
最近一直在做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
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="returns" type="xsd:integer"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="SMSServiceRequest">
</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
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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。