Hi,
I would like to ask some comments on the following issue. Thanks in advance for your help.
It is about to consume a web service on PHP5 with SOAP extension (No Nusoap). The example is to parse a last name to web service and get all the contacts that has the same last name, then display the result on the page. Each set of result should have ID, last name, and first name.
Below is the PHP code:
$lastname = 'Doe';
$client = new SoapClient("http://10.0.0.0/test/ContactValidation.asmx?WSDL", array('trace' => 1, 'exceptions' => 0));
$params->lastname = $lastname;
$object = $client->validateContact($params);
$result = $object->validateContactResult;
echo "Request :<br>", htmlspecialchars($client->getLastRequest()), "<br><br>";
echo "Response :<br>", htmlspecialchars($client->getLastResponse()), "<br><br>";
echo "Output from print_r(): ";
print_r($result);
I was able to request and get the response from it. The return will consist one or more results as in dataset. The response seems like the correct in XML (<id>200011479</id><lastname>Doe</lastname><firstname>Jane</firstname>.)
Request :
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://10.0.0.0/test/">
<SOAP-ENV:Body>
<ns1:validateContact>
<ns1:lastname>Doe</ns1:lastname>
</ns1:validateContact>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Response :
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<validateContactResponse xmlns="http://10.0.0.0/test/">
<validateContactResult>
<xs:schema id="ResultSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="ResultSet" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Result">
<xs:complexType>
<xs:sequence>
<xs:element name="id" type="xs:string" minOccurs="0" />
<xs:element name="lastname" type="xs:string" minOccurs="0" />
<xs:element name="firstname" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<ResultSet xmlns="">
<Result diffgr:id="Result1" msdata:rowOrder="0" diffgr:hasChanges="inserted">
<id>200011478</id>
<lastname>Doe</lastname>
<firstname>John</firstname>
</Result>
<Result diffgr:id="Result2" msdata:rowOrder="1" diffgr:hasChanges="inserted">
<id>200011479</id>
<lastname>Doe</lastname>
<firstname>Jane</firstname>
</Result>
</ResultSet>
</diffgr:diffgram>
</validateContactResult>
</validateContactResponse>
</soap:Body>
</soap:Envelope>
I was looking for something similar like this when using print_r() and trying to see each key and element of the object.
[Just an example]
stdClass Object (
[Result] => stdClass Object (
[id] => 200011478
[lastname] => Doe
[firstname] => John
)
[Result] => stdClass Object (
[id] => 200011479
[lastname] => Doe
[firstname] => Jane
)
)
Instead, the output was presented as one whole string:
Output from print_r():
stdClass Object (
[schema] => [any] =>
200011478DoeJohn200011479DoeJane
)
Have done some research and studied it on php.net. Still, couldn't figure out what went wrong and couldn't read each value individually like <?=$result->lastname?>. Is there anything that I missed? (I have searched the site and still "stuck". Pardon me if I overlooked.) Any insight would be greatly appreciated!