Created
February 23, 2011 19:37
-
-
Save wilsaj/841006 to your computer and use it in GitHub Desktop.
Flask + Soaplib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import soaplib | |
from soaplib.core.service import rpc, soap, DefinitionBase | |
from soaplib.core.model.primitive import String, Integer | |
from soaplib.core.server import wsgi | |
from soaplib.core.model.clazz import Array | |
from flask import Flask | |
flask_app = Flask(__name__) | |
@flask_app.route("/") | |
def hello(): | |
return "Hello World!" | |
class HelloWorldService(DefinitionBase): | |
@rpc(String,Integer,_returns=Array(String)) | |
def say_hello(self,name,times): | |
results = [] | |
for i in range(0,times): | |
results.append('Hello, %s'%name) | |
return results | |
if __name__=='__main__': | |
try: | |
from werkzeug.wsgi import DispatcherMiddleware | |
soap_application = soaplib.core.Application([HelloWorldService], 'tns') | |
wsgi_application = wsgi.Application(soap_application) | |
flask_app.wsgi_app = DispatcherMiddleware(flask_app.wsgi_app, { | |
'/soap': wsgi_application, | |
}) | |
flask_app.run() | |
except ImportError: | |
print "Error: example server code requires Python >= 2.5" |
Author
wilsaj
commented
Jul 22, 2011
via email
On Fri, Jul 22, 2011 at 9:32 AM, ametade < ***@***.***>wrote:
Hi,
The code works perfectly when I try it on my dev machine running the flask
server but when I try to run this code on a Linux + Apache + mod_wsgi
server I'm always getting 404 errors.
Hard to figure out that one without more information. What do the apache
logs look like?
I also created some extra functions with route decorators and they work
fine on the mod_wsgi server, but not the '/soap' url or '/soap/?wsdl'. Do
you know what might me happening?
When you dispatch, you are handing over the endpoint (and anything after it)
to the soaplib app. If you set up Flask routes on '/soap' or
'/soap/<somethingelse>', those routes will never get routed because that
route is delegated to soaplib only.
Thanks
… ##
Reply to this email directly or view it on GitHub:
https://gist.github.com/841006
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment