Exception in thread "main" org.apache.axis2.AxisFault:
Connection
> refused: connect
I think this speaks enough for itself. You don't even read what you're
sending us, so why should we?
Burak
Hi, Burak:
I certainly read what I sent.
In part 1, serve-side is tornadows, the axis2-client cannot invoke the
server, and returns nothing
In part 2, server-side is soaplib. the server is developed in ubuntu
linux,"172.16.2.46" is its ip,
when you exceute "w3m
http://localhost:7789/?wsdl", "w3m
http://127.0.0.1:7789/?wsdl", thay are okay.
but "w3m: Can't load
http://172.16.2.46:7789/?wsdl." is failed.
I develop tornadows in the same ubuntu linux, "w3m
http://172.16.2.46:8000/SMSService?wsdl" is also okay.
In the local area network, "http://172.16.2.46:8000/SMSService?wsdl" is
also okay.
I do not know the difference of tornadows and soaplib, so sent them
together.
w_jiaxiaolei@pabb-608:~$ ifconfig
eth0 Link encap:Ethernet HWaddr 1c:6f:65:d4:b3:d3
inet addr:172.16.2.46 Bcast:172.16.255.255 Mask:255.255.0.0
inet6 addr: fe80::1e6f:65ff:fed4:b3d3/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2538292 errors:0 dropped:0 overruns:0 frame:0
TX packets:979243 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:276531149 (276.5 MB) TX bytes:621990155 (621.9 MB)
Interrupt:32 Base address:0xa000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:2619 errors:0 dropped:0 overruns:0 frame:0
TX packets:2619 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:410554 (410.5 KB) TX bytes:410554 (410.5 KB)
w_jiaxiaolei@pabb-608:~$ w3m
http://172.16.2.46:8000/SMSService?wsdl
w_jiaxiaolei@pabb-608:~$ w3m
http://127.0.0.1:7789/?wsdl
w_jiaxiaolei@pabb-608:~$ w3m
http://localhost:7789/?wsdl
w_jiaxiaolei@pabb-608:~$ w3m
http://172.16.2.46:7789/?wsdl
w3m: Can't load
http://172.16.2.46:7789/?wsdl.
Okay, now let's forget part 2, look at part 1 only. How to invoke a python
webservice server-side(tornadow, soaplib, or others) using Axis2?
------------------------------ part 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”
<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">
<wsdl:types>
<xsd:schema targetNamespace="http://127.0.1.1:8000/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: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"/>
</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.
------------------------------- 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.*
<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"/>
<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"/>
</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)
...
-- Jia Xiaolei