Web2py SOAP and local wsdl file

1,042 views
Skip to first unread message

Barry Bridges

unread,
Jun 17, 2013, 9:44:06 AM6/17/13
to web...@googlegroups.com

Hi all,
I'm trying to create a SOAP server which uses a local wsdl file supplied by a third party. How can I use this within Web2py


Thanks
Barry

Derek

unread,
Jun 17, 2013, 2:30:55 PM6/17/13
to web...@googlegroups.com
You aren't quite making sense. You want to create a soap server with web2py, but you want that to consume another soap server's api? why?

Massimo Di Pierro

unread,
Jun 18, 2013, 1:22:55 AM6/18/13
to web...@googlegroups.com
If you have WSDL service you can connect to is using suds (pip insall suds)

from suds.client import Client
client = Client(wsdl_service)
result = client.service.function(input)

here function is a service which must provided by in WSLD.

I understand you have the opposite problem. Create a server that is compliant with given WSDL. Actually I need to do same for a project and I have been unable to. I am not sure this is logically possible because the WSDL contains enough info to generate the service.

Barry Bridges

unread,
Jun 18, 2013, 2:55:40 AM6/18/13
to web...@googlegroups.com
Hi Massimo,
Your correct in that I need to create a server that is complaint with someone else's WSDL. I have to full spec of the API, but need to provide that to the client devices. If I use pysimplesoap, the WSDL is created for me but is not totally compliant/formted to the customers spec. So the issue is can I serve up my WSDL file rather than the interally generated one.

You'll have to forgive my terminology but I'm and embedded engineer not a web developer so it's all a little new to me.

Massimo Di Pierro

unread,
Jun 18, 2013, 3:33:20 AM6/18/13
to web...@googlegroups.com
If you find a solution to your problem let me know. I have a similar problem. The process usually is [create server] -> [generate wsdl] -> [create client from wsdl]. I would like to see an example ot [create server from wsdl].

Barry Bridges

unread,
Jun 18, 2013, 8:41:14 AM6/18/13
to web...@googlegroups.com

Michele Comitini

unread,
Jun 19, 2013, 5:01:56 AM6/19/13
to web...@googlegroups.com
Barry, Massimo,

SOAP is not part of my daily work anymore (very happy with that!) , but a few years ago I have been using ZSI a lot for creating web services from WSDL documents.  It worked great and SOAP seems not evolved much since, I then suppose ZSI could be even better today.
That was before web2py even existed so I have no idea if it can be used without too much troubles inside web2py.  I remember it generates some code, scattered in a few files, well written, but it could be that adjustments by hand need to be done to make it work on a web2py request inside a controller...

mic



2013/6/18 Barry Bridges <barrybr...@gmail.com>
--
 
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Mariano Reingart

unread,
Jun 19, 2013, 5:18:16 AM6/19/13
to web...@googlegroups.com
Do you have the wsdl file?

It would be relatively possible to create a server from the WSDL if it
is not too complicated (at least using pysimplesoap)

The trick would be read and parse the WSDL with the soap client to see
the expected structures.
You can se the client.services attribute, it contains the parsed wsdl
and you can even manipulate it:
http://code.google.com/p/pysimplesoap/wiki/SoapClient
The same structure can be used to expose the method (controllers'
function in web2py), as the serialization mechanism is the same.

I did this once to simulate a production webservice, and there is no
need to generate code or clasess (again, at least using pysimplesoap),
it is just formating the xml as desired using python data types
(mainly dicts and lists, for most webservices)

Best regards,

Mariano Reingart
http://www.sistemasagiles.com.ar
http://reingart.blogspot.com

Massimo Di Pierro

unread,
Jun 19, 2013, 7:17:35 AM6/19/13
to web...@googlegroups.com
Can you provide a simple example?

Mariano Reingart

unread,
Jun 19, 2013, 12:27:34 PM6/19/13
to web...@googlegroups.com
This is the original webservice:

https://wswhomo.afip.gov.ar/wsfev1/service.asmx?WSDL

And this is the "simulator" made with web2py:

http://www.sistemasagiles.com.ar/simulador/wsfev1/call/soap

Attached is the web2py sample controller

Steps:

1. Analyse the original web service description:
client = SoapClient(wsdl="https://wswhomo.afip.gov.ar/wsfev1/service.asmx?WSDL")

2. Extract the input and output structures
client.services['Service']['ports']['ServiceSoap12']['operations']['FECAESolicitar']['input']
client.services['Service']['ports']['ServiceSoap12']['operations']['FECAESolicitar']['output']
The returned structures are {'FECAESolicitar': *{u'Auth': *{u'Token':
<type 'unicode'>, u'Sign': <type 'unicode'>, u'Cuit': <type 'long'>}*,
u'FeCAEReq': *{u'FeCabReq': *{u'CantReg': <type 'int'>, ... , you need
to do some clean up (for example, replace <type 'unicode'> with just
unicode, remove the * that marks an ordered dict, etc.)

3. Decorate your function accordingly
@service.soap('FECAESolicitar',
returns={'FECAESolicitarResult': {...},
args={
'Auth': {'Token': str, 'Sign': str, 'Cuit': str},
...}

4. Modify the original WSDL with the web2py location and test

To go further, you may need to adjust some xml parameters like the
namepaces, prefixes, and so on, to reproduce the exact behaviour of
the original webservice, it may be tricky but it should be doable.

Best regards.
On Wed, Jun 19, 2013 at 8:17 AM, Massimo Di Pierro
wsfev1.py

Massimo Di Pierro

unread,
Jun 20, 2013, 1:42:26 AM6/20/13
to web...@googlegroups.com
Thank you. Very useful.
Reply all
Reply to author
Forward
0 new messages