如何在 zeep 中使用 wsdl 的每种方法发送 header?

how can I send header with each methods of wsdl in zeep?

我是 zeep 的新手。并尝试实现一个 wsdl:http://leon.leonardotravel.com/Leon.svc/wsdl

我必须像这样发送请求:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
    <Search xmlns="http://tempuri.org/">
      <Header>
        <AgentId>agentid</AgentId>
        <Password>password</Password>
        <Username>username</Username>
      </Header>
      <Search>
        <CheckIn>2017-06-10</CheckIn>
        <CheckOut>2017-06-12</CheckOut>
        <CityId>4339</CityId>
        <CurrencyId>2</CurrencyId>
        <HotelId>122079</HotelId>
        <PaxCountryId>2</PaxCountryId>
        <DefaultPhotoInclude>false</DefaultPhotoInclude>
        <GeoCoordinatesInclude>false</GeoCoordinatesInclude>
        <HotelAddressInclude>false</HotelAddressInclude>
        <HotelDescriptionInclude>false</HotelDescriptionInclude>
        <HotelNameInclude>true</HotelNameInclude>
        <MaxResponseTime>0</MaxResponseTime>
        <SearchRooms>
          <SearchRoom>
            <Adult>1</Adult>
            <Child1Age>0</Child1Age>
            <Child2Age>0</Child2Age>
            <Child3Age>0</Child3Age>
            <Quantity>1</Quantity>
          </SearchRoom>
        </SearchRooms>
      </Search>
    </Search>
  </s:Body>
</s:Envelope>

当我想使用这个 wsdl 的每个方法时,我应该发送 header。 你能帮帮我吗?!

既然 google 带我来这里,我将 post 我的发现。

为了在客户端进行的每次调用中发送相同的 SOAP headers,我这样做了,并使用一些愚蠢的替代品来满足一般消费:

from zeep import Client, xsd
client = Client(
    wsdl_url,
    transport=transport,
)

header = xsd.ComplexType(
    xsd.Sequence([
        xsd.Element('SomeString', xsd.String()),
        xsd.Element('SomeBoolean', xsd.Boolean()),
    ])
)

headers = [ header(SomeString='Hello', SomeBoolean=True) ]
client.set_default_soapheaders(headers)

client.service.MakeTheMagic(Stuff=stuff)