Pergunta

Eu estou tentando fazer um pequeno webservice "Olá Mundo" com Django seguindo alguns tutoriais, mas eu estou batendo a mesma barreira mais e mais. Eu defini uma view.py e soaplib_handler.py:

view.py:

from soaplib_handler import DjangoSoapApp, soapmethod, soap_types

class HelloWorldService(DjangoSoapApp):

    __tns__ = 'http://saers.dk/soap/'

    @soapmethod(_returns=soap_types.Array(soap_types.String))
    def hello(self):
      return "Hello World"

soaplib_handler.py:

from soaplib.wsgi_soap import SimpleWSGISoapApp
from soaplib.service import soapmethod
from soaplib.serializers import primitive as soap_types

from django.http import HttpResponse


class DjangoSoapApp(SimpleWSGISoapApp):

    def __call__(self, request):
        django_response = HttpResponse()
        def start_response(status, headers):
            status, reason = status.split(' ', 1)
            django_response.status_code = int(status)
            for header, value in headers:
                django_response[header] = value
        response = super(SimpleWSGISoapApp, self).__call__(request.META, start_response)
        django_response.content = "\n".join(response)

        return django_response

E parece que a "resposta = Super ...." linha está me dando problemas. Quando eu carregar /hello_world/services.wsdl mapeados em url.py eu recebo:

AttributeError em /hello_world/service.wsdl 'Module' objeto não tem nenhum atributo 'tostring'

Para a mensagem de erro completa, veja aqui: http://saers.dk:8000/hello_world/service.wsdl

Você tem alguma sugestão a respeito de porque eu recebo este erro? E onde está ElementTree definido?

Foi útil?

Solução

@zdmytriv A linha

soap_app_response = super(BaseSOAPWebService, self).__call__(environ, start_response)

deve ser semelhante

soap_app_response = super(DjangoSoapApp, self).__call__(environ, start_response)

então o seu exemplo funciona.

Outras dicas

não sei se isso vai resolver o seu problema, mas o decorador em seu Olá função diz que é supor para retornar uma matriz de cadeia, mas na verdade você está devolvendo uma String

Tente _returns = soap_types.String vez

Ray

copiar / colar do meu serviço:

# SoapLib Django workaround: http://www.djangosnippets.org/snippets/979/
class DumbStringIO(StringIO):
    """ Helper class for BaseWebService """
    def read(self, n): 
        return self.getvalue()

class DjangoSoapApp(SimpleWSGISoapApp):
    def __call__(self, request):
        """ Makes Django request suitable for SOAPlib SimpleWSGISoapApp class """

        http_response = HttpResponse()

        def start_response(status, headers):
            status, reason = status.split(' ', 1)
            http_response.status_code = int(status)

            for header, value in headers:
                http_response[header] = value

        environ = request.META.copy()
        body = ''.join(['%s=%s' % v for v in request.POST.items()])
        environ['CONTENT_LENGTH'] = len(body)
        environ['wsgi.input'] = DumbStringIO(body)
        environ['wsgi.multithread'] = False

        soap_app_response = super(BaseSOAPWebService, self).__call__(environ, start_response)

        http_response.content = "\n".join(soap_app_response)

        return http_response

trecho tem um bug. Leia últimos dois comentários de que url.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top