2

I am trying to create a client that consumes WSDL file and produces a proper SOAP message. This is how I'm creating the client:

client = Client(
        wsdl=wsdl
        ,transport = transport
        ,wsse = Signature('key.pem', 'cert.pem')
    )

The comments in the zeep code say it should produce XML akin to this:

  <soap:Header>
    <wsse:Security mustUnderstand="true">
      <wsu:Timestamp>
        <wsu:Created>2015-06-25T21:53:25.246276+00:00</wsu:Created>
        <wsu:Expires>2015-06-25T21:58:25.246276+00:00</wsu:Expires>
      </wsu:Timestamp>
    </wsse:Security>
  </soap:Header>

However it doesn't add mustUnderstand attribute and the TimeStamp is blank. Does anyone have an idea how to ensure these fields are set correctly?

ierdna
  • 5,753
  • 7
  • 50
  • 84

1 Answers1

4

    from datetime import datetime, timedelta
    from lxml import etree
    from zeep import Client
    from zeep.wsse import utils
    from zeep.plugins import HistoryPlugin

    # Справочники
    wsdl = 'http://claim-test2.isb.az:8903/cib/svc/wsdl/codetable.wsdl'
    username, password = 'ws', '********'
    bussines_user = '********'


    class UsernameTokenTimestamp:
        def __init__(self, username, password=None):
            self.username = username
            self.password = password

        def apply(self, envelope, headers):
            security = utils.get_security_header(envelope)

            created = datetime.now()
            expired = created + timedelta(seconds=5 * 60)

            token = utils.WSSE.UsernameToken()
            token.extend([
                utils.WSSE.Username(self.username),
                utils.WSSE.Password(self.password),
                utils.WSSE.Nonce('43d74dda16a061874d9ff27f2b40e017'),
                utils.WSSE.Created(utils.get_timestamp(created)),
            ])

            timestamp = utils.WSU('Timestamp')
            timestamp.append(utils.WSU('Created', utils.get_timestamp(created)))
            timestamp.append(utils.WSU('Expires', utils.get_timestamp(expired)))

            security.append(timestamp)
            security.append(token)

            #  
            # headers['Content-Type'] = 'application/soap+xml;charset=UTF-8'

            return envelope, headers

        def verify(self, envelope):
            pass


    history = HistoryPlugin()
    client = Client(
        wsdl=wsdl,
        wsse=UsernameTokenTimestamp(username=username, password=password),
        plugins=[history]
    )

dibrovsd
  • 89
  • 4