1

我是使用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 的每个方法时,我应该发送标题。你能帮助我吗?!

4

1 回答 1

1

由于谷歌将我带到这里,我将发布我的发现。

为了在客户端进行的每次调用中发送相同的 SOAP 标头,我这样做了,并为一般消费做了一些愚蠢的替换:

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)
于 2018-06-04T19:39:37.900 回答