djangospyne

Requested resource '{spyne.examples.django}' not found


I am trying to develop a soap service in Django using Spyne. I've cloned spyne for app 'Hello_world' in Django application, but I get an error. Could anyone help me with it please?

My codes is similar to the one below:

app = Application([HelloWorldService], 'spyne.examples.hello.http',
    in_protocol=HttpRpc(),
    out_protocol=Soap11(),
)

but the following error occurs:

<faultcode>soap11env:Client.ResourceNotFound</faultcode>
<faultstring>Requested resource '{spyne.examples.django}' not found</faultstring>
<faultactor/>

Solution

  • There is no handler defined for the root url:

    https://github.com/plq/spyne/blob/b3b3f198b6148a498cdaeda9897307e0c5b1aac1/examples/django/rpctest/urls.py#L40

    After you switch the input protocol to HttpRpc and do this:

    curl -D - localhost:8000/hello_world/
    

    You get:

    <?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>
    

    That's because you didn't specify which method to call.

    The HelloWorldService in that example defines the say_hello function. You can call that.

    curl -D - "localhost:8000/hello_world/say_hello"
    

    Now this finds the method but you get a traceback (which I won't include here) because of non-validated input being passed to your function.

    If you pass all the parameters:

    curl -D - "localhost:8000/hello_world/say_hello?times=5&name=Fatemeh"
    

    You get:

        <?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>
    

    You may want to enable validation to avoid Server exceptions. First we add Mandatory markers to input types:

        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
    

    Then we enable soft validation (the only one for HttpRpc)

    app = Application([HelloWorldService], 'spyne.examples.hello.http',
        in_protocol=HttpRpc(validator='soft'),
        out_protocol=Soap11(),
    )
    

    After server restart and the following:

    curl -D - "localhost:8000/hello_world/say_hello"
    

    You get:

    <class 'spyne.model.complex.say_hello'>.name member must occur at least 1 times.
    

    I hope this helps!