# 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:types>
<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">
<wsdl:operation name="getPrice">
<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">
</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
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(
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.
------------------------------- part 2 --------------------------------------------
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.
xmlns:tns="SMSService.SMSService" xmlns:typens="SMSService.SMSService"
name="SMSService">
<types>
<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">
<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">
</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
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)
...