- 
          
- 
        Couldn't load subscription status. 
- Fork 605
Description
I described the problem in this discussion: #1460
Im generating a soap request with factories from the types in the WSDL.
The generated request is faulty containing a credentials tag twice:
<?xml version='1.0' encoding='utf-8'?>
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
 <soap-env:Body>
  <ns0:GetDeptListRequest xmlns:ns0="http://atoss.com/ses/services/masterdata/dept-1.0">
   <ns1:Credentials xmlns:ns1="http://atoss.com/ses/services/masterdata/types-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns1:ListServiceRequest">
   <ns1:Credentials>
    <ns1:Logonid>xxx</ns1:Logonid>
    <ns1:Clientno>xxx</ns1:Clientno>
    <ns1:Password>xxx</ns1:Password>
   </ns1:Credentials>
   </ns1:Credentials> 
  </ns0:GetDeptListRequest>
 </soap-env:Body>
</soap-env:Envelope>
Notice the duplicate Credentials tags.
Also notice that the first Credentials open tag has the type ListServiceRequest:
<ns1:Credentials xmlns:ns1="bla" xmlns:xsi="bla" xsi:type="ns1:ListServiceRequest">
This is clearly a bug.
The request generated from SOAPUI looks like this and works just fine:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
                                xmlns:dept="http://atoss.com/ses/services/masterdata/dept-1.0" 
                                xmlns:typ="http://atoss.com/ses/services/masterdata/types-1.0">
   <soapenv:Header/>
   <soapenv:Body>
      <dept:GetDeptListRequest>
         <typ:Credentials>
            <typ:Logonid>xx</typ:Logonid>
            <typ:Clientno>xx</typ:Clientno>
            <typ:Password>xxx</typ:Password>
         </typ:Credentials>
      </dept:GetDeptListRequest>
   </soapenv:Body>
</soapenv:Envelope>
I thinks it has to do with the GetDeptListRequest being an extension of the ListServiceRequest type in the WSDL.
<xs:element xmlns:xs="http://www.w3.org/2001/XMLSchema" name="GetDeptListRequest">
  <xs:complexType xmlns:xs="http://www.w3.org/2001/XMLSchema">
   <xs:complexContent xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:extension xmlns:xs="http://www.w3.org/2001/XMLSchema" base="wstypes:ListServiceRequest"/>
   </xs:complexContent>
 </xs:complexType>
</xs:element>
Using zeep 4.3.1
WSDL: see attachment to the second post in this discussion: #1460
Minimal code:
from zeep import Client, Settings
from zeep.transports import Transport
from requests.auth import HTTPBasicAuth
from requests import Session
WSDL_URL = "https://ases-abn.example.com/SES/services/masterdata/dept-1.0.wsdl"
USER = "xxx"
PWD = "yyy"
CLIENTNO = '123'
 
# Override post to store xml request and response
# see https://github.com/mvantellingen/python-zeep/issues/603
class Transport(Transport):
    def post(self, address, message, headers):
        self.xml_request = message.decode('utf-8')
        print(f"XML Request: {self.xml_request}")
        response = super().post(address, message, headers)
        self.response = response
        print(f"XML Response: {self.response}")
        return response
session = Session()
session.auth = HTTPBasicAuth(USER, PWD)
client = Client(wsdl =WSDL_URL,
                transport = Transport(session=session)# with basic auth
                )
#print(client.wsdl.dump())
credentialsType = client.get_type('ns1:CredentialsType')
listServiceRequest = client.get_type('ns1:ListServiceRequest')
factory = client.type_factory('ns1')
credentials = factory.CredentialsType(
                    Logonid=USER,
                    Password=PWD,
                    Clientno=CLIENTNO
                    )
request_data = factory.ListServiceRequest(
                    Credentials = credentials
                    )
response = client.service.GetDeptList(request_data)
#print(response.content)