I gotta consume a SOAP service from PHP but I keep failing to get the response. Maybe it's a problem with the format or the call or idk. I can for example get all the functions names from the server with the __getFunctions() method. But when I try to invoke any function I keep getting:
SOAP-ERROR: Encoding: Cannot find encoding
Below is the code.
$wsdl = "https://testing.memoryefactura.com/Memory.FEManager/WebService/CFEService.svc?wsdl";
$parameters = array('Rut' => 'XXXXX',
'CommerceCode' => 'XXXXX',
'TerminalCode' => 'XXXXX',
'Timeout' => 5000);
$options = array(
'style' => SOAP_RPC,
'use' => SOAP_ENCODED,
'soap_version' => SOAP_1_1,
'cache_wsdl' => WSDL_CACHE_NONE,
'connection_timeout' => 15,
'trace' => true,
'exceptions' => true,
);
try {
$soap = new SoapClient($wsdl, $options);
$HeaderSecurity = array(
'stream_context' => stream_context_create(array(
'http' => array(
'header' => array('username' => 'XXXXX',
'password' => 'XXXXX'
)
),
)),
);
$header[] = new SoapHeader("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security", $HeaderSecurity);
$soap->__setSoapHeaders($header);
$data = $soap->Ping($parameters);
} catch (Exception $e) {
die($e->getMessage());
}
var_dump($data);
styleandusefrom your options, they should not be used in WSDL mode. Instead of catchingExceptiontry catchingSoapFaultwhich can give you more error details: php.net/manual/en/soapfault.soapfault.phpusernameandpassword???SoapClient->__call('Ping', Array) #1 {main}). Yes, if i dont send those headers gives authentication error.SoapFaultto get additional details, not justgetMessage().