Server.py
from soaplib.service import soapmethod
from soaplib.serializers.primitive import String, Integer, Array
from soaplib.wsgi_soap import SimpleWSGISoapApp
class HelloWorldService(SimpleWSGISoapApp):
@soapmethod(String, _returns=String)
def says(self,name):
return name
def make_client():
from soaplib.client import make_service_client
client = make_service_client('http://0.0.0.0:7889', HelloWorldService())
return client
if __name__=='__main__':
try:
from wsgiref.simple_server import make_server
server = make_server('0.0.0.0', 7889, HelloWorldService())
print "listening on 0.0.0.0:7889"
server.serve_forever()
except ImportError:
print "Error: example server code requires Python >= 2.5"
client.py
from hello import make_client
a = make_client()
print a.says('hello,world')
运行:
python server.py
python client.py