我无法弄清楚如何使用此WSDL interface。我对WSDL(以及一般的SOAP)没有经验。
这完全超出了我的想象。我的情况如下。我有一个使用REST接口与后端通信的Web应用程序。后端需要与提到的WSDL接口进行通信,以便为Web应用程序提供它请求的信息。
所以
[Client] <-- REST --> [Server] <-- SOAP --> [XLedger]
我想我需要一个针对完整SOAP新手的教程。现在有太多的差距,我无法从文章中推断出我需要的东西。或者,一位有用的SO成员可以向我展示一些示例代码以帮助我入门?
更具体地说,我对GetTimesheetEntriesData及其提供的属性感兴趣。我只是希望能够调用getter并将数据发送到Web应用程序(在智能手机上运行)。
我甚至不确定我是否在这里提出正确的问题,但如何使用WSDL界面获取用户时间表数据?
[编辑]
以下是身份验证界面:https://ws.xledger.net/WS/Common/Lib/Authentication.asmx?WSDL
答案 0 :(得分:1)
好的我明白了。我必须首先使用suds。
import httplib
import urllib2 as u2
from suds.transport.http import HttpTransport
class HTTPSClientAuthHandler(u2.HTTPSHandler):
def __init__(self, key, cert):
u2.HTTPSHandler.__init__(self)
self.key = key
self.cert = cert
def https_open(self, req):
# Rather than pass in a reference to a connection class, we pass in
# a reference to a function which, for all intents and purposes,
# will behave as a constructor
return self.do_open(self.getConnection, req)
def getConnection(self, host, timeout=300):
return httplib.HTTPSConnection(host, key_file=self.key, cert_file=self.cert)
class HTTPSClientCertTransport(HttpTransport):
def __init__(self, key, cert, *args, **kwargs):
HttpTransport.__init__(self, *args, **kwargs)
self.key = key
self.cert = cert
def u2open(self, u2request):
"""
Open a connection.
@param u2request: A urllib2 request.
@type u2request: urllib2.Request.
@return: The opened file-like urllib2 object.
@rtype: fp
"""
url = u2.build_opener(HTTPSClientAuthHandler(self.key, self.cert))
if self.u2ver() < 2.6:
return url.open(u2request)
else:
return url.open(u2request, timeout=self.options.timeout)
.
.
.
def consume_soap():
from suds.client import Client
from datetime import date
from calendar import monthrange
transport = HTTPSClientCertTransport('auth/key_no_passphrase.pem', 'auth/cert.pem')
client = Client(XLedgerInterface.WSDL_EXPORT_PATH, transport=transport)
year = date.today().year
month = date.today().month
first_date = str(date(year, month, 1))
last_date = str(date(year, month, monthrange(year, month)[1]))
xml = client.service.GetTimesheetEntriesData(sUserName=XLedgerInterface.USER_ID,
sKey=XLedgerInterface.KEY,
sApplication=XLedgerInterface.APPLICATION_NAME,
iEntityCode=XLedgerInterface.ENTITY_CODE,
dDateFrom=first_date,
dDateTo=last_date,
sFreeText='',
sFilter='',
eOption="Open")
return self._get_as_json(xml)