我使用spyne.protocol.soap.soap11
开发了一项网络服务
当运行在Django命令(python管理runserver)时,它按预期工作:
1.我可以从$ url获取wsdl文件?wsdl
2.拨打网络服务并获得回复
但是当部署在apache服务器中时,它会响应$ url?wsdl,状态为200,但没有内容:
Connection →close
Content-Length →0
Content-Type →text/xml; charset=utf-8
Date →Mon, 16 Oct 2017 02:22:08 GMT
Server →Apache/2.2.15 (CentOS)
我也可以调用Web服务,服务器执行我想要的操作(将数据插入数据库)但apache服务器响应没有内容。
注意:以上都是在同一台机器上运行,同样是python
我在Google和StackOverflow中搜索过,但没有类似的问题。
1 class AbnormalService(ServiceBase):
2 @rpc(Unicode, Unicode, Integer, Integer, Integer, _returns=Unicode)
3 def abnormal(ctx, username, password, locationID, abnormalID, smallAbnormalID):
4 try:
5 AbnormalRecord.objects.create(location_id=locationID, abnormal_id=abnormalID, smallAbnormal_id=smallAbnormalID)
6 except Exception as ex:
7 return str(ex)
8 return "OK"
这是我的间谍网络服务视图。并且第5行在apache服务器上执行了(数据库添加了一行)。它应该响应:
<?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:abnormalResponse>
<tns:abnormalResult>OK</tns:abnormalResult>
</tns:abnormalResponse>
</soap11env:Body>
</soap11env:Envelope>
但标题内容长度为0的响应,以及网络服务确实已经执行
我尝试将WSGIApplicationGroup%{GLOBAL}添加到httpd.conf,没有任何改变。
我的django设置:
网址:
url(r'^uploadrecords', DjangoView.as_view(
services=[views.AbnormalService], tns='spyne.examples.django',
in_protocol=Soap11(validator='lxml'),
out_protocol=Soap11(),
cache_wsdl=False)),
url(r'^api/', DjangoView.as_view(application=views.app)),`<br>
views:
class AbnormalService(ServiceBase):
@rpc(Unicode, Unicode, Integer, Integer, Integer, _returns=Unicode)
def abnormal(ctx, username, password, locationID, abnormalID, smallAbnormalID):
try:
AbnormalRecord.objects.create(location_id=locationID, abnormal_id=abnormalID, smallAbnormal_id=smallAbnormalID)
except Exception as ex:
return str(ex)
return "OK"
app = Application([AbnormalService],
'spyne.examples.django',
in_protocol=Soap11(validator='lxml'),
out_protocol=Soap11(validator='lxml'),
)
abnormal_service = csrf_exempt(DjangoApplication(app))
设置:
WSGIApplicationGroup %{GLOBAL}
WSGIPythonPath /var/www/html/kanban
Listen 9000
<VirtualHost *:9000>
<Directory "/var/www/html/kanban/kanban">
<Files wsgi.py>
Order allow,deny
Allow from all
</Files>
WSGIApplicationGroup %{GLOBAL}
</Directory>
WSGIScriptAlias / /var/www/html/kanban/kanban/wsgi.py
WSGIApplicationGroup %{GLOBAL}
ServerName dummy-host.example.com
ErrorLog logs/django_log
CustomLog logs/django_custom_log common
</VirtualHost>