I have created a custom Magento2 Soap API to get data from a third party server and save it into Magento DB. Everything is working fine with data processing. Now When I print the result it is in an Object form but I need it in XML format only. Here is the code I am using to make the request:
$wsdlurl = 'MagentoStore/soap?wsdl&services=CustomDataApiManagementV1';
$token = 'XXXXXXXXXXXX';
$opts = ['http' => ['header' => "Authorization: Bearer " . $token]];
$context = stream_context_create($opts);
$addArgs = array('xmldata'=> 'testData');
try{
$soapClient = new SoapClient($wsdlUrl);
$soapClient->setSoapVersion(SOAP_1_2);
$soapClient->setStreamContext($context);
$soapResponse = $soapClient
->CustomDataApiManagementV1ProcessData($addArgs);
print_r($soapResponse);
}catch(Exception $e){
echo 'error';
}
This print_r($soapResponse) is showing result as below:
stdClass Object ( [result] => success )
I need result in XML format only.
Please do let me know if anyone has already worked on it.