how to Consume external NetTcp SOAP service in Web2Py

142 views
Skip to first unread message

Gopi

unread,
Jun 23, 2014, 1:39:22 PM6/23/14
to web...@googlegroups.com
Hi All.. I am new to web2py. Is there a way to call external NetTcp SOAP service in Web2Py. What are the best practices to call such  services in Web2Py?

Massimo Di Pierro

unread,
Jun 24, 2014, 1:48:13 PM6/24/14
to web...@googlegroups.com
web2py ships with pysimplesoap. It is documented on google code.

Dave S

unread,
Jul 7, 2014, 9:32:28 PM7/7/14
to web...@googlegroups.com

As a newcomer, I found it easy to implement.

(@service.soap(various args that get used to form the wsdl XML)   )

/dps
 

Dave S

unread,
Jul 7, 2014, 10:50:22 PM7/7/14
to web...@googlegroups.com

Whoops, replied from the wrong side of the soap factory.

 I am not sure I've consumed SOAP from my controllers.  I have clients that use suds, but I may have started down that road before finding web2py.  It was serving SOAP that brought me here.

/dps

Matheus Cardoso

unread,
Jul 9, 2014, 9:47:42 AM7/9/14
to web...@googlegroups.com
There are some examples in the web2py's book and lots of more in pysimplesoap repository, as Massimo said. Besides, I just created a WS and a SOAP client with basic authentication and I used some of many forms of consuming a WS like this:


ws_user
= "your_login"
ws_pass
= "your_password"

#I am using web2py to create the client
from gluon.contrib.pysimplesoap.client import SoapClient
import base64
encoded
= base64.b64encode('%s:%s' % (ws_user, ws_pass)).replace('\n', '')

# The following IS NOT the address of the WSDL from WS
ws_location
= "your_web_service_location"
ws_action
= "your_web_service_action"
ws_namespace
= "your_web_service_namespace"

# Create the client
client_soap
= SoapClient(
    location
= ws_location,
    action
= ws_action, # SOAPAction
   
namespace = ws_namespace,
    soap_ns
='soap', trace = False, ns = False, exceptions=True, http_headers={'Authorization': "Basic %s" % encoded})

Enjoy! :)

Dave S

unread,
Jul 30, 2014, 1:43:12 PM7/30/14
to web...@googlegroups.com
I kind of let this lay around until last night, when I had the happy idea that this would help me with a particular user problem.  I have stand-alone SOAP clients using SUDS or Java, but I have a user where installing those clients could be problematic.  So I tried as below, but failed.

Note that instead of doing this from a console, I was trying to make this a function within my controller, so that it could be used by clinking a link on a page I'm serving.  I have an instance of web2py on an old Fedora, where it has been running happily for nearly a year.  The SOAP provider works fine there.  In addition, there is a summary page I can browse to.  This works from the local browser, but when I try to use the SOAP client code I get connection refused.  So I turned to another instance of web2py, running on Centos machine.  I can access it just fine via my stand-alone SOAP clients and the summary page, but again I get "connection refused".
(from urlib2.py, line 1165, Errno 111 per the ticket.; HTTP 500 sent to the client machine).

tcpdump on the Centos machine shows it being the access to the function that acts as the SOAP client, and console output indicates that instantiating the client is the problem.  I've tried with both the location parameters as shown below, or with the wsdl parameter as in the first example on pysimplesoap, and with and without setting the Authorization header (the servers are on an internal network, and still using Rocket, and so I've turned off authorization on the SOAP provider;  the stand-alone clients send the authorization header, but it isn't used).  One of the stand-alone clients uses pyssimplesoap.

Any suggestions?

Dave
/dps

Dave S

unread,
Jul 30, 2014, 3:41:50 PM7/30/14
to web...@googlegroups.com

On Wednesday, July 30, 2014 10:43:12 AM UTC-7, Dave S wrote:
I kind of let this lay around until last night, when I had the happy idea that this would help me with a particular user problem.  I have stand-alone SOAP clients using SUDS or Java, but I have a user where installing those clients could be problematic.  So I tried as below, but failed.

Note that instead of doing this from a console, I was trying to make this a function within my controller, so that it could be used by clinking a link on a page I'm serving. 

When I use -S welcome to have a shell, I get the same connection refused error trying to instantiate the client.

Oooooh, blush.  I forgot the port number in the wsdl URL.

/dps



Dave S

unread,
Jul 30, 2014, 9:24:34 PM7/30/14
to
So it's not too bad consuming a service I provide for myself, but I'm also interested in a service provided by a third-party device.

This particular service doesn't use "action", instead it uses "control" and "flag".

In a SUDS client (sudsclient = suds.client.Client(serviceurl, transport),
I use sudsclient.factory.create('ns2:typename') to create the xmlnodes,
and in sudsclient.service.XYZService(control, action="", node, flag) use the
settings I've given them (string and integer, respectively) while leaving the action blank (as you see).

The debug info from the SUDS client shows the XML with the usual stuff and the body as follows:
HEADERS: {'SOAPAction':'""', [...], 'Soapaction' : '""'}

and

<?xml version="1.0" encoding=<UTF-8"?><SOAP_ENV:Envelope xmlns:s="http://www/w3/org/ [etc, including 1 proprietary
 and 2 xmlsoap.org] ]>
<SOAD-ENV:Header/><ns1:Body><ns#:XYZService><contrl>STR1</control><action></action><node>NODEIDSTR</node>
<flag>1234</flag></ns#:XYZService></ns1:Body></SOAP-ENV:Envelope>

Does someone have a suggestion how to do this with pysimplesoap?  I'm looking at the source of client.py, but it will take me a while to make sense of it and to find where the corresponding bit to sudsclient.factory.create() is.

Thanks for your help.

Dave
/dps


Reply all
Reply to author
Forward
0 new messages