[omaha] Python SOAP and Apache

freeav8r freeav8r at yahoo.com
Tue May 20 17:00:11 CEST 2008


Jeff,

The key here for us is knowing that you can tell
mod_wsgi how many instances/threads to start and that
they can persist throughout multiple sessions.  Thanks
for the info - It shortcutted the research needed.

Jeff, Mike, Matthew,

Thanks for the feedback.  I hope this info helps
someone else.  We're using cherrypy and soaplib right
now for the prototype.  Setting up soap couldn't be
easier with this combination (16 lines of code for the
server example -- see below).  

The documentation is sparse, but with some digging,
you'd find that the WSDL is dynamically created and
accessable at http://localhost:7789/soap/api.wsdl  

We had no trouble accessing the web service from
python or .net and can share what we learned if anyone
runs into issues.

The static typing of the web service is handled with
the line:

@soapmethod(String,Integer,_returns=Array(String))

=========== Example =====================
from soaplib.wsgi_soap import SimpleWSGISoapApp
from soaplib.service import soapmethod
from soaplib.serializers.primitive import String,
Integer, Array

class HelloWorldService(SimpleWSGISoapApp):

    @soapmethod(String,Integer,_returns=Array(String))
    def say_hello(self,name,times):
        results = []
        for i in range(0,times):
            results.append('Hello, %s'%name)
        #return '|'.join(results)
        return results
        
if __name__=='__main__':
    
    # this example uses CherryPy2.2, use
cherrypy.wsgiserver.CherryPyWSGIServer for CherryPy
3.0
    from cherrypy.wsgiserver import CherryPyWSGIServer
    server =
CherryPyWSGIServer(('localhost',7789),HelloWorldService())
    server.start()


--- Jeff Hinrichs - DM&T <jeffh at dundeemt.com> wrote:

> On Mon, May 19, 2008 at 10:36 AM, freeav8r
> <freeav8r at yahoo.com> wrote:
> > Hi Jeff and all,
> >
> > Thanks for the response.  The WSGI mod appears to
> be
> > what we're looking for to connect to Apache.  We
> need
> > true connection pooling though since we won't know
> > which of many databases to connect to until the
> > individual request is processed.
> >
> > If we are to run the CherryPy application as WSGI
> in
> > apache without requiring the internal CherryPy
> engine
> > to be run (this appears to be the most efficent
> > setup), any suggestions on implementing connection
> > pooling with apache and mysql so that the python
> > application has access to the connections?
> The link I posted,
> http://tools.cherrypy.org/wiki/Databases gives a
> good way to setup your connections on a per thread
> basis for mysql.
> When you are using mod_wsgi, you can tell it (as
> opposed to the
> cherrypy server) how many instances/threads to start
> and set a
> maximum.  How many different DB connections are you
> talking about? In
> the example, they use a simple vector, db, as the
> solution for
> cherrypy.thread_data.  However, nothing precludes
> you from using a
> list or dictionary of connections.
> i.e.
> 
> def connect(thread_index):
>     # Create a connection and store it in the
> current thread
>     cherrypy.thread_data.db = {}
>     cherrypy.thread_data.db['db1'] =
> MySQLdb.connect('host', 'user',
> 'password', 'dbname')
>     cherrypy.thread_data.db['db2'] =
> MySQLdb.connect('host2', 'user2',
> 'password2', 'dbname2')
>     ...
> 
> If you have 20 databases, each thread would have 20
> connections -- 1
> to each db.  Then it would depend on how many
> threads/processes you
> end up starting. I've used similar for an app that
> connected for 4
> different databases.
> 
> hope that helps.
> 
> -jeff
> 
> >
> >
> > -freeav8r
> >
> >
> > --- Jeff Hinrichs - DM&T <jeffh at dundeemt.com>
> wrote:
> >
> >> While I haven't done any SOAP with python, here
> are
> >> some of the things
> >> that I know.
> >>
> >> CherryPy can run under apache via mod_wsgi
> >>
> >
>
http://code.google.com/p/modwsgi/wiki/IntegrationWithCherryPy
> >>  so you
> >> should be able to get yourself all the goodness
> of
> >> apache with pretty
> >> much no code modification.
> >>
> >> Connection Pooling: depends on the database you
> are
> >> using.  Is it
> >> thread-safe?  See
> >> http://tools.cherrypy.org/wiki/Databases for more
> >> insight.
> >>
> >> regards,
> >>
> >> Jeff
> >>
> >> On Mon, May 19, 2008 at 9:53 AM, freeav8r
> >> <freeav8r at yahoo.com> wrote:
> >> > Hi All,
> >> >
> >> > I need to implement a number of SOAP web
> services
> >> in
> >> > Python for an enterprise level system (lots of
> >> > traffic).  Prototypes are up and running on
> >> cherrypy's
> >> > WSGI server without any form of connection
> pooling
> >> for
> >> > the database connections.
> >> >
> >> > Any suggestions on what technologies and
> >> frameworks
> >> > that will allow the following:
> >> >
> >> > 1.  Ability to utilize existing apache web
> servers
> >> > 2.  Connection pooling to a database for the
> >> database
> >> > connections that the web services will consume
> >> > 3.  Generation of WSDL for (and compatibility
> >> with)
> >> > Python, Java, and Microsoft .net clients.
> >> >
> >> > Any suggestions?  Anyone on the list already
> doing
> >> > this?
> >> >
> >> > -freeav8r
> >> >
> >> >
> >> >
> >> >
> >> >
> >> > _______________________________________________
> >> > Omaha Python Users Group mailing list
> >> > Omaha at python.org
> >> > http://mail.python.org/mailman/listinfo/omaha
> >> > http://www.OmahaPython.org
> >> >
> >>
> >>
> >>
> >> --
> >> Jeff Hinrichs
> >> Dundee Media & Technology, Inc
> >> jeffh at dundeemt.com
> >> 402.218.1473
> >> web: www.dundeemt.com
> >> blog: inre.dundeemt.com
> >> _______________________________________________
> >> Omaha Python Users Group mailing list
> >> Omaha at python.org
> >> http://mail.python.org/mailman/listinfo/omaha
> >> http://www.OmahaPython.org
> >>
> >
> >
> >
> >
> > _______________________________________________
> > Omaha Python Users Group mailing list
> > Omaha at python.org
> > http://mail.python.org/mailman/listinfo/omaha
> > http://www.OmahaPython.org
> >
> 
> 
> 
> -- 
> Jeff Hinrichs
> Dundee Media & Technology, Inc
> jeffh at dundeemt.com
> 402.218.1473
> web: www.dundeemt.com
> blog: inre.dundeemt.com
> _______________________________________________
> Omaha Python Users Group mailing list
> Omaha at python.org
> http://mail.python.org/mailman/listinfo/omaha
> http://www.OmahaPython.org
> 



      


More information about the Omaha mailing list