さて、これが私の最初の質問ですので、できる限り最善を尽くします。
Soaplib2.0を使用してPython2.6およびDjango1.4でWebServiceサーバーを実装しようとしています。
Webサービスは機能しており、DjangoはDjango開発サーバーで問題なくサービスを提供しています。
DjangoViewとUrlsのコードは次のとおりです。
views.py
from soaplib.core.service import rpc, DefinitionBase, soap
from soaplib.core.model.primitive import String, Integer, Boolean
from soaplib.core.model.clazz import Array
from soaplib.core import Application
from soaplib.core.server.wsgi import Application as WSGIApplication
from django.http import HttpResponse
class HelloWorldService(DefinitionBase):
@soap(String,Integer,_returns=Array(String))
def say_smello(self,name,times):
results = []
for i in range(0,times):
results.append('Hello, %s'%name)
return results
@soap(String,_returns=Boolean)
def xml(self,xml):
result = xml
return True
@soap(String,_returns=String)
def xml2(self,xml2):
return xml2
class DjangoSoapApp(WSGIApplication):
csrf_exempt = True
def __init__(self, services, tns):
"""Create Django view for given SOAP soaplib services and
tns"""
return super(DjangoSoapApp,
self).__init__(Application(services, tns))
def __call__(self, request):
django_response = HttpResponse()
def start_response(status, headers):
django_response.status_code = int(status.split(' ', 1)[0])
for header, value in headers:
django_response[header] = value
response = super(DjangoSoapApp, self).__call__(request.META,
start_response)
django_response.content = '\n'.join(response)
return django_response
my_soap_service = DjangoSoapApp([HelloWorldService], __name__)
urls.py
url(r'^soap/wsdl$', 'soap.views.my_soap_service'),
url(r'^soap/$', 'soap.views.my_soap_service'),
重要なのは、WebServiceメソッドxmlまたはxml2にXMLを渡し、XMLに含まれる情報を処理することです。エラーが発生します。
「&」のような文字を含まない単純な文字列を渡すと たとえば、すべてが正常に機能します。
まず、sudをインポートし、sudをDebugに設定しましょう。
from suds.client import Client
import logging
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
それでは、deWSの呼び出しを開始しましょう。
WSDL = "http://server.test/soap/wsdl"
client = Client(WSDL)
client.service.xml('x and y')
完璧に動作し、「True」を取得し、SUDSのログはこれを実行していることを示しています。
DEBUG:suds.client:sending to (http://server.test/soap/wsdl)
message:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns0="soap.views" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<ns1:Body>
<ns0:xml>
<ns0:xml>x and y</ns0:xml>
</ns0:xml>
</ns1:Body>
</SOAP-ENV:Envelope>
DEBUG:suds.client:headers = {'SOAPAction': '"xml"', 'Content-Type': 'text/xml; charset=utf-8'}
DEBUG:suds.client:http succeeded:
<?xml version='1.0' encoding='utf-8'?>
<senv:Envelope xmlns:wsa="http://schemas.xmlsoap.org/ws/2003/03/addressing" xmlns:plink="http://schemas.xmlsoap.org/ws/2003/05/partner-link/" xmlns:xop="http://www.w3.org/2004/08/xop/include" xmlns:senc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s0="soap.views" xmlns:s12env="http://www.w3.org/2003/05/soap-envelope/" xmlns:s12enc="http://www.w3.org/2003/05/soap-encoding/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:senv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"><senv:Body><s0:xmlResponse><s0:xml Result>true</s0:xmlResult></s0:xmlResponse></senv:Body></senv:Envelope>
True
しかし、私がそうする場合:
client.service.xml('x & y')
が機能しておらず、sudsタイムアウトで終了し、サーバーがパイプの破損を報告します。これは、sudsログがプッシュしていることを示しています。
DEBUG:suds.client:sending to (http://server.test/soap/wsdl)
message:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns0="soap.views" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<ns1:Body>
<ns0:xml>
<ns0:xml>x & y</ns0:xml>
</ns0:xml>
</ns1:Body>
</SOAP-ENV:Envelope>
DEBUG:suds.client:headers = {'SOAPAction': '"xml"', 'Content-Type': 'text/xml; charset=utf-8'}
そして、これは泡のエラーです:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/site-packages/suds/client.py", line 542, in __call__
return client.invoke(args, kwargs)
File "/usr/lib/python2.6/site-packages/suds/client.py", line 602, in invoke
result = self.send(soapenv)
File "/usr/lib/python2.6/site-packages/suds/client.py", line 643, in send
reply = transport.send(request)
File "/usr/lib/python2.6/site-packages/suds/transport/https.py", line 64, in send
return HttpTransport.send(self, request)
File "/usr/lib/python2.6/site-packages/suds/transport/http.py", line 77, in send
fp = self.u2open(u2request)
File "/usr/lib/python2.6/site-packages/suds/transport/http.py", line 118, in u2open
return url.open(u2request, timeout=tm)
File "/usr/lib/python2.6/urllib2.py", line 391, in open
response = self._open(req, data)
File "/usr/lib/python2.6/urllib2.py", line 409, in _open
'_open', req)
File "/usr/lib/python2.6/urllib2.py", line 369, in _call_chain
result = func(*args)
File "/usr/lib/python2.6/urllib2.py", line 1190, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "/usr/lib/python2.6/urllib2.py", line 1165, in do_open
raise URLError(err)
urllib2.URLError: <urlopen error timed out>
このリンクのおかげで:http://grokbase.com/p/python/soap/125nhj9bdm/python-suds-xml-encoding-issue次のようなWebサービスを投稿すると、はい、わかります。
client.service.xml("x &amp; y")
私はそれを正しく理解します:
DEBUG:suds.client:sending to (http://server.test/soap/wsdl)
message:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns0="soap.views" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<ns1:Body>
<ns0:xml>
<ns0:xml>x &amp; y</ns0:xml>
</ns0:xml>
</ns1:Body>
</SOAP-ENV:Envelope>
DEBUG:suds.client:headers = {'SOAPAction': '"xml"', 'Content-Type': 'text/xml; charset=utf-8'}
True
メソッドxml2を使用して、WebServiceが返されるものを確認できるようにすると、次のようになります。
client.service.xml2("x &amp; y")
そしてSudsのログ:
DEBUG:suds.client:sending to (http://server.test/soap/wsdl)
message:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:ns0="soap.views" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<ns1:Body>
<ns0:xml2>
<ns0:xml2>x &amp; y</ns0:xml2>
</ns0:xml2>
</ns1:Body>
</SOAP-ENV:Envelope>
DEBUG:suds.client:headers = {'SOAPAction': '"xml2"', 'Content-Type': 'text/xml; charset=utf-8'}
DEBUG:suds.client:http succeeded:
<?xml version='1.0' encoding='utf-8'?>
<senv:Envelope xmlns:wsa="http://schemas.xmlsoap.org/ws/2003/03/addressing" xmlns:plink="http://schemas.xmlsoap.org/ws/2003/05/partner-link/" xmlns:xop="http://www.w3.org/2004/08/xop/include" xmlns:senc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s0="soap.views" xmlns:s12env="http://www.w3.org/2003/05/soap-envelope/" xmlns:s12enc="http://www.w3.org/2003/05/soap-encoding/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:senv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"><senv:Body><s0:xml2Response><s0:xml2Result>x & y</s0:xml2Result></s0:xml2Response></senv:Body></senv:Envelope>
x & y
しかし、このバージョンのsudを使用してXMLをJava WebServicesにプッシュするため、問題はSUDSにあるとは思いませんが、このsoaplibの方法は見つかりませんでした。
何か案は?これは私を少し狂ったxDに駆り立てています
私の最終的な目標は、Soaplibを使用してWebサービスを作成し、JavaのsoapクライアントからXMLをプッシュすることです。
ありがとう