Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 71 lines (44 sloc) 2.155 kB
778a28d edit
Gustavo Andrés Angulo authored
1 ---
2 layout: default
3 title: Webservice + WSDL
4 ---
5
6 # Webservice + WSDL
7
379cb8b edit
Gustavo Andrés Angulo authored
8 Optio's [soaplib](http://trac.optio.webfactional.com/) makes it really straightforward to write SOAP web service views by using a decorator to specify types. Plus it's the only Python library, as of today, which is able to generate WSDL documents for your web service.
778a28d edit
Gustavo Andrés Angulo authored
9
10
11
12 import web
13 from soaplib.wsgi_soap import SimpleWSGISoapApp
14 from soaplib.service import soapmethod
15 from soaplib.serializers import primitive as soap_types
16
17 urls = ("/hello", "HelloService",
18 "/hello.wsdl", "HelloService",
19 )
20 render = web.template.Template("$def with (var)\n$:var")
21
22
23
24 class SoapService(SimpleWSGISoapApp):
25 """Class for webservice """
26
27 #__tns__ = 'http://test.com'
28
29 @soapmethod(soap_types.String,_returns=soap_types.String)
30 def hello(self,message):
31 """ Method for webservice"""
32 return "Hello world "+message
33
34
35
fad643e edit
Gustavo Andrés Angulo authored
36 class HelloService(SoapService):
37 """Class for web.py """
778a28d edit
Gustavo Andrés Angulo authored
38 def start_response(self,status, headers):
39 web.ctx.status = status
40 for header, value in headers:
41 web.header(header, value)
42
43
44 def GET(self):
45 response = super(SimpleWSGISoapApp, self).__call__(web.ctx.environ, self.start_response)
46 return render("\n".join(response))
47
48
49 def POST(self):
50 response = super(SimpleWSGISoapApp, self).__call__(web.ctx.environ, self.start_response)
51 return render("\n".join(response))
52
53 app=web.application(urls, globals())
54
55 if __name__ == "__main__":
56 app.run()
57
58
59
fad643e edit
Gustavo Andrés Angulo authored
60
61 You can test it with a soaplib client:
62
63 >>> from soaplib.client import make_service_client
64 >>> from test import HelloService
65 >>> client = make_service_client('http://localhost:8080/hello', HelloService())
66 >>> client.hello('John')
67 'Hello world John'
68
9d7bac7 edit
Gustavo Andrés Angulo authored
69 And you can view the WSDL in [http://localhost:8080/hello.wsdl](http://localhost:8080/hello.wsdl)
70
78a4439 revert
bm authored
71 For more information of webservice see: [soaplib](http://trac.optio.webfactional.com/),
Something went wrong with that request. Please try again.