[spyne] Trying to expose the basic SOAP interface.

Ian Kane Ian.Kane at perrigo.com
Mon Sep 29 20:17:36 UTC 2014


Hi all, first time post here.

I've been following this library for a few weeks and finally decided to try to make use of it for a project.

I've got an application that needs to receive state updates from a communication bus.  The com bus should be able to notify my application through an exposed SOAP service.
Apparently I have a misunderstanding of the library's API as I have yet to demonstrate a successful test-case.  Any insight as to why the below exception is being thrown would be greatly appreciated.
Here is my test case:

##SOAP service test suite.
##File: test.py
import unittest
from lxml import etree
from StringIO import StringIO

from spyne.application import Application
from spyne.service import ServiceBase
from spyne.protocol.soap import Soap11
from spyne.decorator import srpc, rpc
from spyne.model.complex import ComplexModel
from spyne.model.primitive import String, Unicode
from spyne.server.wsgi import WsgiApplication


import logging
logging.basicConfig(level=logging.INFO)


#complex model definition, parameters that will be recieved in SOAP call,
#idea is to save model to the DB.
class IncidentParams(ComplexModel):
    __type_name__ = 'IncidentParams'
    __namespace__ = 'tns'
    IncNum = Unicode.customize(
        max_len = 15,
        pattern = 'INC[0-9]+',
        type_name = 'MajorIncidentNumber')
    number = IncNum


def start_response(code, headers):
    print(code, headers)

class TestService(unittest.TestCase):
    def test_soap_bare_with_complexInput(self):
        #service definition
        class IncidentService(ServiceBase):
            @srpc(IncidentParams, _returns=IncidentParams)
            def create_incident(the_incident):
                #This RPC logs the input and passes it through as the return value.
                s = etree.tostring(the_incident, pretty_print=True)
                logging.info("create_incident: Parameters:%s" % s)
                #Code_to_save_incident_to_DB(the_incident)
                return the_incident

        app = Application([IncidentService], 'tns', in_protocol=Soap11(),
                            out_protocol=Soap11(cleanup_namespaces=True))

        req = """
        <senv:Envelope  xmlns:senv="http://schemas.xmlsoap.org/soap/envelope/"
                        xmlns:tns="tns">
            <senv:Body>
                <tns:create_incident>
                    <tns:IncidentParams>
                        <s0:number>INC0000001</s0:number>
                    </tns:IncidentParams>
                </tns:create_incident>
            </senv:Body>
        </senv:Envelope>
        """

        server = WsgiApplication(app)
        resp = etree.fromstring(''.join(server({
            'QUERY_STRING': '',
            'PATH_INFO': '/create',
            'REQUEST_METHOD': 'GET',
            'SERVER_NAME': 'localhost',
            'wsgi.input': StringIO(req)
        }, start_response, "http://null")))

        print etree.tostring(resp, pretty_print=True)

if __name__ == '__main__':
    unittest.main()

Running the attached script from the interpreter throws this uncaught exception:

Traceback (most recent call last):
  File "test.py", line 46, in test_soap_bare_with_complexInput
    out_protocol=Soap11(cleanup_namespaces=True))
  File "c:\Python27\lib\site-packages\spyne-2.10.10-py2.7.egg\spyne\application.py", line 104, in __init__
    self.in_protocol.set_app(self)
  File "c:\Python27\lib\site-packages\spyne-2.10.10-py2.7.egg\spyne\protocol\xml\_base.py", line 413, in set_app
    xml_schema.build_validation_schema()
  File "c:\Python27\lib\site-packages\spyne-2.10.10-py2.7.egg\spyne\interface\xml_schema\_base.py", line 170, in build_validation_schema
    self.build_schema_nodes(with_schema_location=True)
  File "c:\Python27\lib\site-packages\spyne-2.10.10-py2.7.egg\spyne\interface\xml_schema\_base.py", line 137, in build_schema_nodes
    self.add(cls, set())
  File "c:\Python27\lib\site-packages\spyne-2.10.10-py2.7.egg\spyne\interface\xml_schema\_base.py", line 127, in add
    handler(self, cls, tags)
  File "c:\Python27\lib\site-packages\spyne-2.10.10-py2.7.egg\spyne\interface\xml_schema\model.py", line 61, in simple_add
    interface.get_restriction_tag(cls)
  File "c:\Python27\lib\site-packages\spyne-2.10.10-py2.7.egg\spyne\interface\xml_schema\_base.py", line 131, in get_restriction_tag
    return handler(self, cls)
  File "c:\Python27\lib\site-packages\spyne-2.10.10-py2.7.egg\spyne\interface\xml_schema\model.py", line 246, in unicode_get_restriction_tag
    restriction = simple_get_restriction_tag(interface, cls)
  File "c:\Python27\lib\site-packages\spyne-2.10.10-py2.7.egg\spyne\interface\xml_schema\model.py", line 49, in simple_get_restriction_tag
    restriction.set('base', cls.__extends__.get_type_name_ns(
AttributeError: 'NoneType' object has no attribute 'get_type_name_ns'

NOTICE: This e-mail message and any attachments are confidential and intended solely for use of the intended recipient. If you are not the intended recipient, you should not review, retransmit, convert to hard copy, copy, use or disseminate this e-mail or any attachments to it. If you have received this e-mail in error, please immediately notify us by return e-mail and delete this message and any attachments from your computer system. Please note that if this e-mail message contains a forwarded message or is a reply to a prior message, some or all of the contents of this message or any attachments may not have been produced by the sender. This notice is automatically appended to each e-mail message leaving the senders e-mail domain. Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spyne.io/archives/people/attachments/20140929/6114864d/attachment.html>


More information about the people mailing list