2009-03-22 3 views
0

나는 약간의 튜토리얼에 따라 Django로 "Hello World"webservice를 만들려고 노력하고 있지만, 같은 장벽을 반복해서 반복하고있다.Django soaplib error

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 : 나는 view.py 및 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 

을 그리고 그것은 "응답 = 슈퍼 보인다 ... . "선은 나를 괴롭힌다. 내가 /hello_world/services.wsdl url.py에 매핑로드 할 때 내가 얻을 :

AttributeError /hello_world/service.wsdl '모듈'개체는 전체 오류 메시지에 대한 속성 'tostring'

이 없습니다에 , 여기를 참조하십시오 : http://saers.dk:8000/hello_world/service.wsdl

이 오류가 발생하는 이유에 대한 의견이 있으십니까? ElementTree는 어디에 정의되어 있습니까?

답변

0

이 문제를 해결할 수 있는지를 확인하지만, 함수의 인사에 장식은 문자열 배열을 반환 생각되지만 실제로 문자열

시도 _returns = soap_types.String 대신

를 반환하는 것을 말한다 없습니다 내 서비스에서

레이

+0

네가 맞습니다. http://saers.dk:8000/hello_world/service.wsdl을 호출하면 hello() 메소드가 호출되지 않으므로 다른 문제점이 있습니다. – zinovii

0

복사/붙여 넣기 :

# 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 

장고 snippet 버그가 있습니다. 해당 URL에서 마지막 두 개의 댓글을 읽으십시오.

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

은 다음 예를 작동과 같은 라인

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

@zdmytriv