forked from arskom/spyne
/
helloworld_attach.py
executable file
·61 lines (51 loc) · 2.17 KB
/
helloworld_attach.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
# encoding: utf8
#
# rpclib - Copyright (C) Rpclib contributors
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
#
# FIXME: This example is not tested!
import logging
from rpclib.application import Application
from rpclib.decorator import srpc
from rpclib.interface.wsdl import Wsdl11
from rpclib.protocol.soap import Soap11
from rpclib.service import ServiceBase
from rpclib.model.complex import Array
from rpclib.model.primitive import Integer
from rpclib.model.primitive import String
from rpclib.model.binary import Attachment
from rpclib.server.wsgi import WsgiApplication
class HelloWorldService(ServiceBase):
@srpc(Attachment, Integer, _returns=Array(String), _mtom=True)
def say_hello(name, times):
results = []
for i in range(0, times):
results.append('Hello, %s' % name.data)
return results
if __name__=='__main__':
try:
from wsgiref.simple_server import make_server
except ImportError:
print "Error: example server code requires Python >= 2.5"
logging.basicConfig(level=logging.DEBUG)
logging.getLogger('rpclib.protocol.soap.soap11').setLevel(logging.DEBUG)
application = Application([HelloWorldService], 'rpclib.examples.hello.attachment',
interface=Wsdl11(), in_protocol=Soap11(), out_protocol=Soap11())
server = make_server('127.0.0.1', 7789, WsgiApplication(application))
print "listening to http://127.0.0.1:7789"
print "wsdl is at: http://localhost:7789/?wsdl"
server.serve_forever()