Expose your service via multiple webservice protocols with ease.

simple example for custom wsdl autogeneration

Asked by romankrv on 2011-07-25

Hi.
Please give some simple example for custom wsdl autogeneration.

Thanks

Question information

Language:
English Edit question
Status:
Solved
For:
ladon Edit question
Assignee:
jsgaarde Edit question
Solved by:
romankrv
Solved:
2011-08-03
Last query:
2011-08-03
Last reply:
2011-08-02

This question was reopened

jsgaarde (jakob-simon-gaarde) said : #1

Hi

Can you tell me what you meen by custom wsdl?

romankrv (romankrv) said : #2

for example:
I want to hav in wsdl
 <portType name="myname.
   <service name=
     <operation name="RequestFeature>

etc

thanks

romankrv (romankrv) said : #3

That is:
exist code (ladon code) which generation wsdl" as
class SOAPServiceDescriptor(ServiceDescriptor):

 xsd_type_map = type_to_xsd
 _content_type = 'text/xml'

 def generate(self,servicename,servicenumber,typemanager,methodlist,service_url,encoding): ......

and I want to set "servicename" from generate meth

can simple example for that

Thanks

jsgaarde (jakob-simon-gaarde) said : #4

Ladon follows the wsdl 1.1 specification completely as far as I know:
http://www.w3.org/TR/wsdl

The servicename comes from the name of your serviceclass. Why do you want Ladon to use another name than the one you gave it while implementing your serviceclass?

/ Jakob Simon-Gaarde

romankrv (romankrv) said : #5

Hi Jakob.
I want to continue discuss about create wsdl file:
Can you explain how to create custom wsdl on demaind (auto generation) via ladon ?
Maybe you have some simple example for that.

(custom wsdl --> it is like http://soap.amazon.com/schemas2/AmazonWebServices.wsdl or like
                                               http://tbe.taleo.net/wsdl/WebAPI.wsdl )
Thanks

jsgaarde (jakob-simon-gaarde) said : #6

What changes should the custom wsdl make?

romankrv (romankrv) said : #7

For example i want to set
soapAction = "myURI"

your lib not have in

def generate(self,servicename,servicenumber,typemanager,methodlist,service_url,encoding):

that definition.

that have only soapAction tag with NULL definition
as:

 for m in methodlist:
                        ...
                        ....
   soapaction.setAttribute('soapAction','')

------------------------------------

so that parametr not configurable but i don't want override that function

Can you made more flexible for that?

Thanks

jsgaarde (jakob-simon-gaarde) said : #8

Hi.

See that was more specific. You have to remember that this is a community project. It's better you tell me exactly if there is a problem so I can fix it for everyone rather that you make your own custom fix that noone else benefits from - that's the way open source works :-)

And in this case you found something that might even be a bug, so please report it as a bug instead of a question.

About the possibility to make custom wsdl, all you have to do is:
1. copy the ladon/interfaces/soap.py module to ie. ladon/interfaces/mysoap.py.
2. edit ladon/interfaces/mysoap.py and in the bottom change the classname SOAPInterface to MYSOAPInterface and make the static method _interface_name() return "mysoap"
3. edit ladon/interfaces/__init__.py add "import ladon.interfaces.mysoap" in the bottom of the file

When you have done that you have two identical interfaces soap and mysoap, changing generate() method in mysoap.py will not affect the soap interface.

The best and most open sourcely thing to do is ofcourse fix/enhance the soap interface on your local system and commit a bug fix, that way you will be credited as a contributer - sounds nice ;-)

Best Regards
Jakob Simon-Gaarde

romankrv (romankrv) said : #9

ok. thanks for instruction.
I done like that but i get error when I start ladon-server

error is:

"""
  File "/home/krv/VIRTUALENVS/LADON/lib/python2.6/site-packages/ladon/interfaces/__init__.py", line 5, in <module>
    from ladon.interfaces import mysoap # added here
  File "/home/krv/VIRTUALENVS/LADON/lib/python2.6/site-packages/ladon/interfaces/mysoap.py", line 4, in <module>
    from ladon.interfaces import expose
ImportError: cannot import name expose

"""

What is problem?

Thanks

jsgaarde (jakob-simon-gaarde) said : #10

Please pastebin mysoap.py
 Den 02/08/2011 14.16 skrev "romankrv" <<email address hidden>
>:
> Question #165951 on ladon changed:
> https://answers.launchpad.net/ladon/+question/165951
>
> Status: Answered => Open
>
> romankrv is still having a problem:
> ok. thanks for instruction.
> I done like that but i get error when I start ladon-server
>
> error is:
>
> """
> File
"/home/krv/VIRTUALENVS/LADON/lib/python2.6/site-packages/ladon/interfaces/__init__.py",
line 5, in <module>
> from ladon.interfaces import mysoap # added here
> File
"/home/krv/VIRTUALENVS/LADON/lib/python2.6/site-packages/ladon/interfaces/mysoap.py",
line 4, in <module>
> from ladon.interfaces import expose
> ImportError: cannot import name expose
>
>
> """
>
>
> What is problem?
>
> Thanks
>
> --
> You received this question notification because you are an answer
> contact for ladon.

jsgaarde (jakob-simon-gaarde) said : #12

Look at my 1. 2. 3. steps again especially step 3 which says: "at the bottom of the file"

Best regards
Jakob Simon-Gaarde

jsgaarde (jakob-simon-gaarde) said : #13

BTW - you don't have to remove the "soap" interface. "soap" and "mysoap" can happily coexist without a problem :-)

romankrv (romankrv) said : #14

Ok. It work(import not crash) but i not see that my def generate in mysoap.py is work only work from soap.py

Why?

Thanks

romankrv (romankrv) said : #15

in debuging i go to soap not mysoap

romankrv (romankrv) said : #16

right like this in __init__.py:

import ladon.interfaces.mysoap
import ladon.interfaces.soap

or right:

import ladon.interfaces.soap
import ladon.interfaces.mysoap

?

jsgaarde (jakob-simon-gaarde) said : #17

The new interface you made is called mysoap so you have to use that. I just tried it, it works perfectly:

ladon/interfaces/mysoap.py : http://paste.ubuntu.com/657252/plain/

jsgaarde (jakob-simon-gaarde) said : #18

You should see a small difference in the wsdl that is created:
<definition
  ...
  mysoap="this_is_mysoap"
   ...>

</definition>

romankrv (romankrv) said : #19

I copy paste your http://paste.ubuntu.com/657252/plain/ to mysoap.py
and it not show me "his_is_mysoap"

what can problem maybe for that?
tnx

romankrv (romankrv) said : #20

if I even delete content in mysoap.py it work. work from soap.py

please help me about that

jsgaarde (jakob-simon-gaarde) said : #21

what is the url to your wsdl?

jsgaarde (jakob-simon-gaarde) said : #22

Have you gone to your web service's webpage with a browser?
1. Open your browser and go to: http://localhost:8000 (if you are running on port 8000)
2. Select the service
3. Find the interface "mysoap" press the description link

Best Regards
Jakob Simon-Gaarde

romankrv (romankrv) said : #23

exactly !

romankrv (romankrv) said : #24

I want to continue issue:
when I try use code for mysoap.py :

from suds.client import Client;
url = 'http://127.0.0.1:8000/TaleoGateway//mysoap/description'
client1 = Client(url)

i get error:

"""

In [20]: client1 = Client(url)
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (279, 0))

---------------------------------------------------------------------------
Exception Traceback (most recent call last)
/home/krv/PROJECTS/hv/<ipython-input-20-c45093bf5023> in <module>()
----> 1 client1 = Client(url)

/home/krv/VIRTUALENVS/LADON/lib/python2.6/site-packages/suds/client.pyc in __init__(self, url, **kwargs)
    110 self.set_options(**kwargs)
    111 reader = DefinitionsReader(options, Definitions)
--> 112 self.wsdl = reader.open(url)
    113 plugins = PluginContainer(options.plugins)
    114 plugins.init.initialized(wsdl=self.wsdl)

/home/krv/VIRTUALENVS/LADON/lib/python2.6/site-packages/suds/reader.pyc in open(self, url)
    150 d = cache.get(id)
    151 if d is None:
--> 152 d = self.fn(url, self.options)
    153 cache.put(id, d)
    154 else:

/home/krv/VIRTUALENVS/LADON/lib/python2.6/site-packages/suds/wsdl.pyc in __init__(self, url, options)
    156 pmd.wrappers['schema'] = repr
    157 self.open_imports()
--> 158 self.resolve()
    159 self.build_schema()
    160 self.set_wrapped()

/home/krv/VIRTUALENVS/LADON/lib/python2.6/site-packages/suds/wsdl.pyc in resolve(self)
    205 """ Tell all children to resolve themselves """
    206 for c in self.children:
--> 207 c.resolve(self)
    208
    209 def build_schema(self):

/home/krv/VIRTUALENVS/LADON/lib/python2.6/site-packages/suds/wsdl.pyc in resolve(self, definitions)
    492 qref = qualify(op.input, self.root, definitions.tns)
    493 msg = definitions.messages.get(qref)
--> 494 if msg is None:
    495 raise Exception("msg '%s', not-found" % op.input)
    496 else:

Exception: msg 'tns:RequestInterview', not-found

"""

If i turn on to default soap.py (in ladon) it is no errors.
Because in mysoap.py it is only copy/paste code from soap.py with changed name class MYSOAPInterface and
 @staticmethod
 def _interface_name():
  return 'mysoap'

Can you reproduce that or what is error and why?

Thanks.

romankrv (romankrv) said : #25

one needs to reloads ipython shell
thx