def main(argv): observer = log.PythonLoggingObserver('twisted') log.startLoggingWithObserver(observer.emit, setStdout=False) wsgi_application = wsgi.Application(application) return run_twisted([(wsgi_application, url)], port)
return fname @soap(String, _returns=Attachment) def get_archived_document(self, file_path): ''' This method loads a document from the specified file path and returns it. If the path isn't found, an exception is raised. ''' if not os.path.exists(file_path): raise Exception("File [%s] not found" % file_path) document = Attachment(file_name=file_path) # the service automatically loads the data from the file. # alternatively, The data could be manually loaded into memory # and loaded into the Attachment like: # document = Attachment(data=data_from_file) return document if __name__ == '__main__': try: from wsgiref.simple_server import make_server soap_app = Application([DocumentArchiver], 'tns') wsgi_app = wsgi.Application(soap_app) server = make_server('localhost', 7889, wsgi_app) server.serve_forever() except ImportError: print "Error: example server code requires Python >= 2.5"
# License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 # from soaplib import Application from soaplib.core.service import soap, DefinitionBase from soaplib.core.model.primitive import String, Integer from soaplib.core.model.binary import Attachment from soaplib.core.model.clazz import Array from soaplib.server import wsgi class HelloWorldService(DefinitionBase): @soap(Attachment, Integer, _returns=Array(String), _mtom=True) def say_hello(self, 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 app = Application([HelloWorldService], "tns") wsgi_app = wsgi.Application(app) server = make_server('localhost', 7789, wsgi_app) server.serve_forever() except ImportError: print "Error: example server code requires Python >= 2.5"