0

我遇到了 Django 1.4 和 Soaplib 2.0 的问题。

当我从客户端发送带有一些大参数的请求时,Django 引发异常并发送此类电子邮件:“ [Django] ERROR (EXTERNAL IP): Internal Server Error: /uri/to/soap/service

Traceback (most recent call last):
File "/path/to/my/project/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 129, in get_response
raise ValueError("The view %s.%s didn't return an HttpResponse object." % (callback.__module__, view_name))

ValueError: The view myproject/library.soap.wsgi.view didn't return an HttpResponse object.

我在服务器端使用http://soaplib.github.io/soaplib/2_0/pages/helloworld.html#declaring-a-soaplib-service提供的普通 @soap 装饰器。

所以,它在服务器配置上看起来像这样:

urls.py里面:

from myproject.server.webservice import WebService

application_view = Application([WebService], 'ws', name='ws').as_django_view()

urlpatterns = patterns(
     url(r'^soap/.*', csrf_exempt( application_view )),
)

myproject/server/webservice.py里面:

 from soaplib.core.service import DefinitionBase
 class WebService(DefinitionBase):
     '''
     The actual webservice class.
     This defines methods exposed to clients.
     '''
     def __init__(self, environ):
         '''
         This saves a reference to the request environment on the current instance
         '''
         self.environ = environ
         super(WebService, self).__init__(environ)

     @soap(Array(Array(String)), _returns=Integer)
     def my_method(self, params):
         return self.process(params)

     def process(self, params):
         #DO SOMETHING HERE

在客户端

 #cfg is my configuration file
 #params is a dictionary 
 client = SoapClient(
                location = cfg.location,
                action = cfg.action, # SOAPAction
                namespace = cfg.namespace, #"http://example.com/sample.wsdl",
                soap_ns= cfg.soap_ns,
                trace = cfg.trace,
                ns = cfg.ns)
 response = client.my_method(params=params)

我试图从我的客户那里发送非常大的字典,但它不起作用。

我怀疑 Django 设置超时并在此过程中关闭我的连接。无论如何增加超时还是由其他原因引起的问题?

顺便说一句,我只使用 Django。我没有配置任何 Apache 或 Nginx。

4

1 回答 1

0

您的process(self, params)方法没有做任何事情(事实上,目前它甚至不是有效的python,因为方法需要在签名后至少有一行代码)。您应该在那里返回一些可用于创建有效肥皂响应的值。

作为旁注,我建议不要再使用soaplib。它被 rpclib 取代,后者现在称为 spyne。还有其他可用的soap 服务器库更关注SOAP 部分(例如pysimplesoap、soapfish)。我发现这很有帮助,因为 SOAP xml 和实际实现之间的抽象往往较少。

于 2014-11-17T12:44:54.310 回答