I have little to no experience in SOAP. And I am interacting with a third party wsdl web service. For this I use PHP’s native SoapClient.
When I send the request I’m getting an error response that states the following:
Schema validation failed: cvc-complex-type.2.4.b: Content of element 'ns2:ScheduleP' is not complete. '{"http://blabla.com/webservices/offer/request":List}' is expected.
The relevant parts of the autogenerated XML are as follow:
<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://blabla.com/webservices/offer/request" xmlns:ns2="http://blabla.com/webservices/datatypes/data" xmlns:ns3="http://blabla.com/webservices/offer/response" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > <SOAP-ENV:Body> <ns1:OfferRequest> <ns1:Header us="my-user" sig="42fc731ee1f1c1" tnr="532709" t="20220301120026"/> <ns1:RequestData> <ns1:ScheduleP xsi:type="ns3:Schedule"> <ns3:List> <ns3:Item/> </ns3:List> </ns1:ScheduleP> </ns1:RequestData> </ns1:OfferRequest> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
If I take the autogenerated XML, change the namespace alias for the List and Item nodes from ns3 to ns1, and send it through postman, it works like a charm.
I think the problem is that both the ns1 namespace and ns2 namespace have a specification for a ScheduleP, List and Item. and the PHP SoapClient is assigning the wrong namespace alias to the List and Item nodes.
Just for clarification, this is the XML that works:
<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://blabla.com/webservices/offer/request" xmlns:ns2="http://blabla.com/webservices/datatypes/data" xmlns:ns3="http://blabla.com/webservices/offer/response" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > <SOAP-ENV:Body> <ns1:OfferRequest> <ns1:Header us="my-user" sig="42fc731ee1f1c1" tnr="532709" t="20220301120026"/> <ns1:RequestData> <ns1:ScheduleP xsi:type="ns3:Schedule"> <ns1:List> <ns1:Item/> </ns1:List> </ns1:ScheduleP> </ns1:RequestData> </ns1:OfferRequest> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
I have no idea on how to proceed, how can one fix this miss-assignation of namespaces?
Advertisement
Answer
Found a solution. Since I have a class that extends PHP’s SoapClient, I can override the __doRequest() function which receives the generated XML String as its first parameter, then you can apply any modification to that string and finally call parent::__doRequest() to send it.