Hi, all:
I was doing something about webservice. What a need to do is using a axis2-client to invoke a webservice developed by python. I tried to provide kinds of webservice server-side, and invoke them by axis2-client. While, all is failed.
In the contents below, I provide the wsdl, axis2 client-side and the server-side made by python. Hope some axis2 experts can give me some points. Thanks ahead.
Method 1:
# server-side: tornadows
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=8000) options['logging'].set('warning')
class SMSService(soaphandler.SoapHandler):
@webservice(_params=xmltypes.Integer,_returns=xmltypes.Integer) def getPrice(self,a): 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()
# wsdl: you can find it in web browser through the url “ http://172.16.2.46:8000/SMSService?wsdl%E2%80%9D <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://127.0.1.1:8000/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:8000/SMSService/getPrice%22%3E wsdl:types <xsd:schema targetNamespace="http://127.0.1.1:8000/SMSService/getPrice%22%3E <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%22/%3E <wsdl:operation name="getPrice"> <soap:operation soapAction="http://127.0.1.1:8000/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:8000/SMSService%22/%3E </wsdl:port> </wsdl:service> </wsdl:definitions>
# 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:8000/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:8000/SMSService/getPrice"); System.out.println(serviceClient.invokeBlocking(opAddEntry, new Object[] {1}, classes)[0]); } } # NOTE: the client get nothing from sever-side and server-side get nothing from Axis2-client.
Apart from it, I made a server-side using soaplib. Still be failed though.
# server-side: soaplib
from soaplib.wsgi_soap import SimpleWSGISoapApp from soaplib.service import soapmethod from soaplib.serializers.clazz import ClassSerializer from soaplib.serializers.primitive import String, Integer, Array, DateTime
class SMSService(SimpleWSGISoapApp): @soapmethod(_returns=Integer) def getPrice(self): return 11
if __name__=='__main__': try: from wsgiref.simple_server import make_server server = make_server('localhost', 7789,SMSService()) server.serve_forever() except ImportError: print "Error: example server code requires Python >= 2.5"
#wsdl: I cannot get wsdl form web browser, and I get the wsdl using "w3m http//localhost:7789/?wsdl' from the server-side.
<definitions xmlns:plnk="http://schemas.xmlsoap.org/ws/2003/05/partner-link/ " xmlns:tns="SMSService.SMSService" xmlns:typens="SMSService.SMSService" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi=" http://www.w3.org/1999/XMLSchema- instance" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="SMSService.SMSService" name="SMSService"> <types> <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="SMSService.SMSService"> <xs:element name="getPriceResponse" type="tns:getPriceResponse"/> <xs:complexType name="getPrice"> xs:sequence/ </xs:complexType> <xs:complexType name="getPriceResponse"> xs:sequence <xs:element name="getPriceResult" type="xs:int"/> </xs:sequence> </xs:complexType> <xs:element name="getPrice" type="tns:getPrice"/> </schema> </types> <message name="getPrice"/> <message name="getPriceResponse"> <part name="getPriceResponse" element="tns:getPriceResponse"/> </message> <portType name="SMSService"> <operation name="getPrice" parameterOrder="getPrice"> <documentation/> <input name="getPrice" message="tns:getPrice"/> <output name="getPriceResponse" message="tns:getPriceResponse"/> </operation> </portType> <plnk:partnerLinkType name="SMSService"> <plnk:role name="SMSService"> <plnk:portType name="tns:SMSService"/> </plnk:role> </plnk:partnerLinkType> <binding name="SMSService" type="tns:SMSService"> <soap:binding style="document" transport=" http://schemas.xmlsoap.org/soap/http%22/%3E <operation name="getPrice"> <soap:operation soapAction="getPrice" style="document"/> <input name="getPrice"> <soap:body use="literal"/> </input> <output name="getPriceResponse"> <soap:body use="literal"/> </output> </operation> </binding> <service name="SMSService"> <port name="SMSService" binding="tns:SMSService"> <soap:address location="http://localhost:7789/?wsdl%22/%3E </port> </service> </definitions>
# client: Java Axis2
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_soaplib {
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:7789"; 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(url2, "SMSService.SMSService"); System.out.println(serviceClient.invokeBlocking(opAddEntry, new Object[] {1}, classes)[0]); } }
# output: Exception in thread "main" org.apache.axis2.AxisFault: Connection refused: connect at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430) at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:197) at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75) at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:404) at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:231) at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:443) at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:406) at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229) at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165) at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:555) at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:531) at org.apache.axis2.rpc.client.RPCServiceClient.invokeBlocking(RPCServiceClient.java:102) at client.client_for_python_soaplib.main(client_for_python_soaplib.java:25) Caused by: java.net.ConnectException: Connection refused: connect at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333) at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366) at java.net.Socket.connect(Socket.java:519) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.commons.httpclient.protocol.ReflectionSocketFactory.createSocket(ReflectionSocketFactory.java:140) at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:125) at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707) at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1361) at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387) at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397) at org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:621) at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:193) ... 11 more
Thanks again for your time and sprit. Any info is welcome!
-- Jia Xiaolei