Fixing Issue With PHPs SoapClient Overwriting Duplicate Attribute and Tag Names
Join the DZone community and get the full member experience.
Join For FreeThe setting:
An SOAP request contains an Id attribute – and an element with the exact name in the response (directly beneath the element containing the attribute – an immediate child):
<res z:Id="i123"> <Id>foobar</Id> </res>
The problem is that the generated result object from the SoapClient (at least of PHP 5.2.12) contains the attribute value, and not the element value. In our case we could ignore the z:Id attribute, as it was simply an Id to identify the element in the response (this might be something that ASP.NET or some other .NET component does).
Our solution is to subclass the internal SoapClient and handle the __doRequest method, stripping out the part of the request that gives the wrong value for the Id field:
class Provider_SoapClient extends SoapClient { public function __doRequest($request, $location, $action, $version) { $result = parent::__doRequest($request, $location, $action, $version); $result = preg_replace('/ z:Id="i[0-9]+"/', '', $result); return $result; } }
This removes the attribute from all the values (there is no danger that the string will be present in any other of the elements. If there is – be sure to adjust the regular expression). And voilá, it works!
Published at DZone with permission of Mats Lindh, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
What Is Istio Service Mesh?
-
Building A Log Analytics Solution 10 Times More Cost-Effective Than Elasticsearch
-
Microservices With Apache Camel and Quarkus
-
Web Development Checklist
Comments