我正在尝试使用Spyne在Django中开发一个soap服务。我已经在Django应用程序中克隆了应用程序'Hello_world‘的spyne,但我得到了一个错误。有谁能帮我一下吗?
我的代码类似于下面的代码:
app = Application([HelloWorldService], 'spyne.examples.hello.http',
in_protocol=HttpRpc(),
out_protocol=Soap11(),
)但会出现以下错误:
<faultcode>soap11env:Client.ResourceNotFound</faultcode>
<faultstring>Requested resource '{spyne.examples.django}' not found</faultstring>
<faultactor/>发布于 2019-10-31 13:52:49
没有为根url定义处理程序:
将输入协议切换为HttpRpc并执行以下操作后:
curl -D - localhost:8000/hello_world/你会得到:
<?xml version='1.0' encoding='UTF-8'?>
<soap11env:Envelope xmlns:soap11env="http://schemas.xmlsoap.org/soap/envelope/">
<soap11env:Body>
<soap11env:Fault>
<faultcode>soap11env:Client.ResourceNotFound</faultcode>
<faultstring>Requested resource u'{spyne.examples.django}' not found</faultstring>
<faultactor></faultactor>
</soap11env:Fault>
</soap11env:Body></soap11env:Envelope>这是因为您没有指定要调用的方法。
该示例中的HelloWorldService定义了say_hello函数。你可以这么说。
curl -D - "localhost:8000/hello_world/say_hello"现在,它找到了该方法,但您得到了一个回溯(我不会在这里包含),因为未验证的输入被传递给了您的函数。
如果您传递所有参数:
curl -D - "localhost:8000/hello_world/say_hello?times=5&name=Fatemeh"你会得到:
<?xml version='1.0' encoding='UTF-8'?>
<soap11env:Envelope xmlns:soap11env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="spyne.examples.django">
<soap11env:Body><tns:say_helloResponse>
<tns:say_helloResult>
<tns:string>Hello, Fatemeh</tns:string>
<tns:string>Hello, Fatemeh</tns:string>
<tns:string>Hello, Fatemeh</tns:string>
<tns:string>Hello, Fatemeh</tns:string>
<tns:string>Hello, Fatemeh</tns:string>
</tns:say_helloResult></tns:say_helloResponse></soap11env:Body></soap11env:Envelope>您可能希望启用验证以避免Server异常。首先,我们将Mandatory标记添加到输入类型:
from spyne import M
class HelloWorldService(Service):
@rpc(M(Unicode), M(Integer), _returns=Iterable(Unicode))
def say_hello(ctx, name, times):
for i in range(times):
yield 'Hello, %s' % name然后我们启用软验证(唯一用于HttpRpc的验证)
app = Application([HelloWorldService], 'spyne.examples.hello.http',
in_protocol=HttpRpc(validator='soft'),
out_protocol=Soap11(),
)在服务器重新启动和以下操作之后:
curl -D - "localhost:8000/hello_world/say_hello"你会得到:
<class 'spyne.model.complex.say_hello'>.name member must occur at least 1 times.我希望这能帮到你!
发布于 2019-10-30 18:52:55
您可能还需要使用in_protocol Soap11。
from spyne.application import Application
app = Application([HelloWorldService], 'spyne.examples.hello.http',
in_protocol=Soap11(validator='lxml'),
out_protocol=Soap11(),
)你可以检查ref link。
https://stackoverflow.com/questions/58622048
复制相似问题