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”
<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.
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)
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
Hi,
I'm trying to connect to the SOAP interface of an innovaphone system.
I'm using the following code to connect to the WSDL file:
from suds.client import Client
> from suds.xsd.doctor import ImportDoctor, Import
> from suds.transport.http import HttpAuthenticated
>
> imp = Import('http://schemas.xmlsoap.org/soap/encoding/')
> imp.filter.add('http://innovaphone.com/pbx')
> imp.filter.add('http://innovaphone.com/binding')
>
> d = ImportDoctor(imp)
> url = 'http://localhost/pbx800.wsdl'
> t = HttpAuthenticated(username='****', password='****')
>
> client = Client(url, transport=t, doctor=d)
>
> print client
> print client.service.Version()
>
The WSDL file I'm using is the same as at:
http://www.innovaphone.com/wsdl/pbx800.wsdl
With the 5th to last line (soap:address location) edited to point to our
PBX server.
running the above script results in the following error:
File "sudstest.py", line 16, in <module>
> print client.service.Version()
> File
> "/usr/lib/python2.6/site-packages/suds-0.4-py2.6.egg/suds/client.py", line
> 542, in __call__
> return client.invoke(args, kwargs)
> File
> "/usr/lib/python2.6/site-packages/suds-0.4-py2.6.egg/suds/client.py", line
> 602, in invoke
> result = self.send(soapenv)
> File
> "/usr/lib/python2.6/site-packages/suds-0.4-py2.6.egg/suds/client.py", line
> 643, in send
> result = self.succeeded(binding, reply.message)
> File
> "/usr/lib/python2.6/site-packages/suds-0.4-py2.6.egg/suds/client.py", line
> 678, in succeeded
> reply, result = binding.get_reply(self.method, reply)
> File
> "/usr/lib/python2.6/site-packages/suds-0.4-py2.6.egg/suds/bindings/binding.py",
> line 149, in get_reply
> soapenv.promotePrefixes()
> AttributeError: 'NoneType' object has no attribute 'promotePrefixes'
>
When I quote out the "print client.service.Version()" line, it displays all
the methods from the WSDL file, but when I leave it uncommented, the "print
client" line doesn't get printed before the error comes up.
Any idea what's causing this error?
I'm using python version 2.6.6 and suds version 0.4
Thanks in advance!
-Remy
Hi all,
I'm trying to access this ws:
from suds.client import Client
from suds.transport.http import HttpAuthenticated
url="https://aris.infocamere.it/parixgatenazionale/services/gate?wsdl"
t = HttpAuthenticated(username='username', password='password')
client = Client(url, transport=t)
result = client.service.RicercaImpresePerCodiceFiscale()
and this is the response:
DEBUG:suds.xsd.query:(u'string', u'http://schemas.xmlsoap.org/soap/encoding/'), not-found
Traceback (most recent call last):
File "test_parix.py", line 12, in <module>
client = Client(url, transport=t)
File "build/bdist.linux-x86_64/egg/suds/client.py", line 119, in __init__
File "build/bdist.linux-x86_64/egg/suds/servicedefinition.py", line 57, in __init__
File "build/bdist.linux-x86_64/egg/suds/servicedefinition.py", line 85, in addports
File "build/bdist.linux-x86_64/egg/suds/bindings/rpc.py", line 39, in param_defs
File "build/bdist.linux-x86_64/egg/suds/bindings/binding.py", line 441, in bodypart_types
suds.TypeNotFound: Type not found: '(string, http://schemas.xmlsoap.org/soap/encoding/, )'
Could someone please give me some help?
thanks
j
HI, all:
Recently I am doing something about python webservice. With the help of
some groups, most of problems has been solved.
Now, how to pass SOAP heasers makes me confused. I try to get help from
web, such as
http://stackoverflow.com/questions/2469988/how-to-pass-soap-headers-into-py…
,
http://stackoverflow.com/questions/2964867/add-header-section-to-soap-reque…,
they indeed provide some valuable advises, but the problem still exists. I
will describe it in detail as follows:
part 1: I need to construct this soapheaders using SUDS.
<soapenv:Header xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<ReqSOAPHeader soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next"
soapenv:mustUnderstand="0" xmlns="http://common.v1_0.obj.protocol.xxt">
<serviceCode>PABB4BEIJING</serviceCode>
<servicePwd>QWERTPABB</servicePwd>
</ReqSOAPHeader>
</soapenv:Header>
part 2: my code
import suds
def test_sms9():
#step 1: import a encode
from suds.xsd.doctor import ImportDoctor, Import
imp = Import('http://schemas.xmlsoap.org/soap/encoding/')
d = ImportDoctor(imp)
#step 2: set the logging
import logging
logging.basicConfig(level=logging.ERROR)
# step 3: construt client
url = "
http://211.137.45.104:9006/LnXxtCpInterface/services/LNXxtSyncService?wsdl"
client =
suds.client.Client(url,doctor=d,cache=None,xstq=False,faults=False)
# step 4: create the header
from suds.sax.element import Element
from suds.sax.attribute import Attribute
code = Element('serviceCode').setText('PABB4BEIJING')
pwd = Element('servicePwd').setText('QWERTPABB')
header_list = [code, pwd]
client.set_options(soapheaders=header_list)
# setp 5: provide the parameters for soap body
item1 =
"{'msgid':'1234567890','bizcode':'15140237310','serviceId':'1234567','recomobile':'15110791945','sendtime':'1322573860','content':'hi,
this is just a test. you can ignore it. --jiaxiaolei'}"
item2 =
"{'msgid':'1234567891','bizcode':'15140237310','serviceId':'1234567','recomobile':'15110791946','sendtime':'1322573870','content':'hi,
this is just a test. you can ignore it. --jiaxiaolei'}"
req = [item1, item2]
aoss = client.factory.create('ArrayOf_soapenc_string')
aoss.item = req
print 'client', client
output = client.service.sendMt(aoss)
print 'SOAP Request:\n', client.last_sent(), '\n'
print 'SOAP Response:\n', client.last_received(), '\n'
print 'the return: \n', output, '\n'
#output:
SOAP Request:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns0="service.global.v1_0.wsdl.protocol.xxt"
xmlns:ns1="http://www.w3.org/2001/XMLSchema"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" x
mlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/
encoding/">
<SOAP-ENV:Header>
<serviceCode>PABB4BEIJING</serviceCode>
<servicePwd>QWERTPABB</servicePwd>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns0:sendMt>
<mtInfo xsi:type="ArrayOf_soapenc_string">
<item
xsi:type="ns1:string">{'msgid':'1234567890','bizcode':'151402
37310','serviceId':'1234567','recomobile':'15110791945','sendtim
e':'1322573860','content':'hi, this is just a
test. you can ignore it. --jiaxiaolei&
apos;}</item>
<item
xsi:type="ns1:string">{'msgid':'1234567891','bizcode':'151402
37310','serviceId':'1234567','recomobile':'15110791946','sendtim
e':'1322573870','content':'hi, this is just a
test. you can ignore it. --jiaxiaolei'}</item>
</mtInfo>
</ns0:sendMt>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
SOAP Response:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="
http://www.w3.org/2001/XMLSchema">
<soapenv:Body>
<soapenv:Fault>
<faultcode>soapenv:Server.generalException</faultcode>
<faultstring/>
<detail>
<ns1:fault xmlns:ns1="service.global.v1_0.wsdl.protocol.xxt"
href="#id0"/>
<ns2:exceptionName xmlns:ns2="http://xml.apache.org/axis/
">xxt.protocol.obj.v1_0.common.ServiceException</ns2:exceptionName>
<ns3:hostname xmlns:ns3="http://xml.apache.org/axis/
">ln_xxt_mh01</ns3:hostname>
</detail>
</soapenv:Fault>
<multiRef xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:ns4="http://common.v1_0.obj.protocol.xxt"
xsi:type="ns4:ServiceException" soapenc:root="0" soapenv:encodingStyle="
http://schemas.xmlsoap.org/soap/encoding/" id="id0">
<messageId xsi:type="soapenc:string">SEV_0003</messageId>
<text xsi:type="soapenc:string">SoapHeader is null</text>
</multiRef>
</soapenv:Body>
</soapenv:Envelope>
the return:
(500, (detail){
fault =
(fault){
_href = "#id0"
}
exceptionName = "xxt.protocol.obj.v1_0.common.ServiceException"
hostname = "ln_xxt_mh01"
})
Then, I modify the code:
# step 4: create the header
from suds.sax.element import Element
from suds.sax.attribute import Attribute
code = Element('serviceCode').setText('PABB4BEIJING')
pwd = Element('servicePwd').setText('QWERTPABB')
header_list = [code, pwd]
client.set_options(soapheaders=header_list)
==>
# step 4: create the header
from suds.sax.element import Element
from suds.sax.attribute import Attribute
code = Element('serviceCode').setText('PABB4BEIJING')
pwd = Element('servicePwd').setText('QWERTPABB')
reqsoapheader = Element('ReqSOAPHeader').insert(code)
reqsoap_attribute = Attribute('xmlns', "http://schemas.acme.eu/")
reqsoapheader.append(reqsoap_attribute)
client.set_options(soapheaders=reqsoapheader)
# output:
SOAP Request:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns0="service.global.v1_0.wsdl.protocol.xxt"
xmlns:ns1="http://www.w3.org/2001/XMLSchema"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" x
mlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/
encoding/">
<SOAP-ENV:Header>
<ReqSOAPHeader xmlns="http://schemas.acme.eu/">
<serviceCode>PABB4BEIJING</serviceCode>
</ReqSOAPHeader>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
.... # NOTE: the body is omitted.
SOAP Response:
# it's same with mentioned above.
I try to change the code to "reqsoapheader =
Element('ReqSOAPHeader').insert([code,pwd]) ". it failed.
Last, how to generate a soapheader as :
<SOAP-ENV:Header>
<ReqSOAPHeader>
<serviceCode>xxxx</serviceCode>
<servicePwd>yyy</servicePwd>
</ReqSOAPHeader>
<SOAP-ENV:Header>
Any advice will be highly appreciated. Thanks and regards ahead for the the
time and concentration.
Thanks again!
-- Jia Xiaolei