1

我无法弄清楚如何使用这个WSDL 接口。我对 WSDL(和一般的 SOAP)的经验为零。

这一切都完全超出了我的想象。我的情况如下。我有一个使用 REST 接口与后端通信的 Web 应用程序。后端需要与提到的 WSDL 接口进行通信,以向 Web 应用程序提供它所请求的信息。

所以

[Client] <-- REST --> [Server] <-- SOAP --> [XLedger]

我想我需要一个针对完整 SOAP 新手的教程。现在有太多的差距,我无法从文章中推断出我需要的东西。或者,也许有帮助的 SO 成员可以向我展示一些示例代码以帮助我入门?

更具体地说,我对GetTimesheetEntriesData及其提供的属性感兴趣。我只想能够调用 getter 并将数据发送到网络应用程序(在智能手机上运行)。

我什至不确定我在这里问的问题是否正确,但是如何使用 WSDL 接口获取用户时间表数据?

[编辑]

这是身份验证的接口:https ://ws.xledger.net/WS/Common/Lib/Authentication.asmx?WSDL

4

1 回答 1

1

好的,我想通了。我必须先使用泡沫

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)
于 2013-08-05T13:49:28.453 回答