Web サービス用の python クライアントを作成することに興味があります。テスト目的で、単純なスタブ サーバーを作成することも非常に興味深いことです。Python 2.3 と ZSI 2.0 を使用しています。
私の問題は、サーバーから例外を返すことができないことです。
wsdl で SOAP エラーに使用される型の例外を発生させると、TypeError 'exceptions must be classes, instances, or strings (deprecated), not EmptyStringException_Def' が発生します。これは、障害オブジェクトが Exception のサブクラスではないことを意味していると思いましたが、この方法で生成されたコードを変更しても役に立ちませんでした。もちろん、生成されたコードを変更する必要がない方がはるかに優れています:)
応答の一部として障害オブジェクトを返すと、それは単に無視されます。
ZSI での障害処理に関するドキュメントは見つかりませんでした。ヒントはありますか?
これは、入力文字列が空の場合にソープ エラーを返す、spellBackwards メソッドを 1 つだけ持つ非常に単純なサービスのサーバーのサンプル コードです。
#!/usr/bin/env python
from ZSI.ServiceContainer import AsServer
from SpellBackwardsService_services_server import *
from SpellBackwardsService_services_types import *
class SpellBackwardsServiceImpl(SpellBackwardsService):
def soap_spellBackwards(self, ps):
response = SpellBackwardsService.soap_spellBackwards(self, ps)
input = self.request._in
if len(input) != 0:
response._out = input[::-1]
else:
e = ns0.EmptyStringException_Def("fault")
e._reason = "Empty input string"
# The following just produces an empty return message:
# response._fault = e
# The following causes TypeError
# raise e
return response
AsServer(port=8666, services=[SpellBackwardsServiceImpl(),])