0

スタンドアロンアプリケーションとして実行しているソープサーバーがあります。つまり、単に実行するだけですpython mysoapserver.py

ただし、wsgi を使用して apache2 経由でアクセスできるようにしたいと考えています。

以下は、現在のコードの一部のコードの抜粋です。

インポート:

from pysimplesoap.server import SoapDispatcher, SOAPHandler, WSGISOAPHandler

コードの抜粋

dispatcher = SoapDispatcher(
'TransServer',
location = "http://127.0.0.1:8050/",
action = 'http://127.0.0.1:8050/', # SOAPAction
namespace = "http://example.com/sample.wsdl", prefix="ns0",
trace = True,
ns = True)

#Function
def settransactiondetails(sessionId,msisdn,amount,language):
    #Some Code here
    #And more code here
    return {'sessionId':sid,'responseCode':0}

# register the user function
dispatcher.register_function('InitiateTransfer', settransactiondetails,
    returns={'sessionId': str,'responseCode':int}, 
    args={'sessionId': str,'msisdn': str,'amount': str,'language': str})

logging.info("Starting server...")
httpd = HTTPServer(("", 8050),SOAPHandler)
httpd.dispatcher = dispatcher
httpd.serve_forever()

wsgiを介してapache2でアクセスできるようにするには、上記のコードをどのように変更する必要がありますか。私が必要とする変更を/etc/apache2/sites-available/defaultファイルに含めることもできます。

4

1 に答える 1

3

wsgi 仕様によると、Python スクリプトで行う必要があるのは、次のように application という名前の変数で wsgi アプリを公開するだけです。

#add this after you define the dispatcher
application = WSGISOAPHandler(dispatcher)

次に、スクリプトを apache のような安全な場所に配置し、使用可能なサイトにWSGIScriptAlias/usr/local/www/wsgi-scripts/ディレクティブを追加します。これにより、 Apache wsgi スクリプト ハンドラーにスクリプトの検索場所とその中で実行するアプリケーションを指示します。

WSGIScriptAlias /your_app_name /usr/local/www/wsgi-scripts/your_script_file

<Directory /usr/local/www/wsgi-scripts>
Order allow,deny
Allow from all
</Directory>

また、mod_wsgi がインストールされていて、pythonpath に pysimplesoap があると仮定すると、正常に動作するはずです。また、mod_wsgi を使用する場合は、おそらく変更して、Apache が使用するパスを使用する必要があることも覚えておいてdispatcher.locationくださいdispatcher.action。この情報は、Apache を使用するかどうかに関係なく、wsdl 定義に残ります。

アプリをスタンドアロンで実行する可能性を維持したい場合は、HTTPServer セクションを置き換えます

logging.info("Starting server...")
httpd = HTTPServer(("", 8050),SOAPHandler)
httpd.dispatcher = dispatcher
httpd.serve_forever()

これとともに:

if __name__=="__main__":
    print "Starting server..."
    from wsgiref.simple_server import make_server
    httpd = make_server('', 8050, application)
    httpd.serve_forever()

さらに詳しい情報が必要な場合は、単純な石鹸の wsgi のドキュメントmod_wsgi ガイドを参照してください。

于 2014-04-17T09:03:15.770 に答える