I'm creating SOAP web service using PHP.
Here is my code..
SoapServer.php
class server{
public function RegisterComplaint($strInputXml){
$str = "<RESULT><complaintNo>09865678</complaintNo></RESULT>";
$arr['RegisterComplaintResult'] = trim($str);
return $arr;
}
}
$custom_wsdl = 'custom.wsdl';
$server = new SoapServer($custom_wsdl);
$server->setClass('server');
$server->handle();
When I call RegisterComplaint using Wizdler(chrome extension) I get below result:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.Insurer.com/webservices/">
<SOAP-ENV:Body>
<ns1:RegisterComplaintResponse>
<ns1:RegisterComplaintResult><RESULT><complaintNo>09865678</complaintNo></RESULT></ns1:RegisterComplaintResult>
</ns1:RegisterComplaintResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Here I want result in below format(special characters to HTML entities):
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.Insurer.com/webservices/">
<SOAP-ENV:Body>
<ns1:RegisterComplaintResponse>
<ns1:RegisterComplaintResult><RESULT><complaintNo>09865678</complaintNo></RESULT></ns1:RegisterComplaintResult>
</ns1:RegisterComplaintResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Does any one know what I have to change for required output?
I tried html_entity_decode() & htmlspecialchars() on $str variable, but it's not working.
The solution as response. (Already quoted out in the comments)
The SoapServer
class awaits an object as return value. This object will be automatically encoded by the server using the definitions from the used wsdl file. If a string is returned, its entities will always be encoded.
class Server
{
public function registerComplaint()
{
$registerComplaintResponse = new stdClass();
$registerComplaintResult = new stdClass();
$result = new \stdClass();
$result->complaintNo = '09865678';
$registerComplaintResult->RESULT = $result;
$registerComplaintResponse->RegisterComplaintResult = $registerComplaintResult;
return $registerComplaintResponse;
}
}
All definitions of return types (complex types) are defined in the wsdl file.