蟒蛇Web的服务:从使用ZSI服务器返回错误
-
22-07-2019 - |
题
我有兴趣写一个python客户端web服务,并为测试目的,将是非常有趣也有一个简单的存根服务器。我使用python 2.3,ZSI 2.0。
我的问题是我不设法从服务器返回一个异常。
如果我提出用于WSDL中的皂故障类型的异常时,得到的TypeError“例外必须是类,实例,或串(不建议使用),而不是EmptyStringException_Def”。我认为这意味着故障对象不是异常的子类,但修改以这种方式并没有帮助生成的代码 - 当然,不必修改生成的代码会好得多:)
如果我返回故障对象作为响应的一部分,它只是忽略。
我找不到任何有关故障的ZSI处理任何文件。任何提示?
下面是一个非常简单的服务的只用一个方法,spellBackwards一个服务器,它应该返回皂故障如果输入的字符串是空的一个示例代码:
#!/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(),])
其他提示
不隶属于 StackOverflow