**SOAP-ERROR:** Encoding: Cannot find encoding












0















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);









share|improve this question

























  • First thing, get rid of style and use from your options, they should not be used in WSDL mode. Instead of catching Exception try catching SoapFault which can give you more error details: php.net/manual/en/soapfault.soapfault.php

    – miken32
    Nov 14 '18 at 21:31











  • And are you really supposed to pass HTTP headers named username and password???

    – miken32
    Nov 14 '18 at 21:32











  • Thanks for the tips. Erased style and use and still the same. Tried catching soupFault and it gives nothing usefull (just this: SoapClient->__call('Ping', Array) #1 {main}). Yes, if i dont send those headers gives authentication error.

    – Martin Chocho
    Nov 14 '18 at 22:02











  • You need to use the specific functions for SoapFault to get additional details, not just getMessage().

    – miken32
    Nov 14 '18 at 22:04













  • Can you share a link to the WSDL?

    – miken32
    Nov 14 '18 at 22:08
















0















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);









share|improve this question

























  • First thing, get rid of style and use from your options, they should not be used in WSDL mode. Instead of catching Exception try catching SoapFault which can give you more error details: php.net/manual/en/soapfault.soapfault.php

    – miken32
    Nov 14 '18 at 21:31











  • And are you really supposed to pass HTTP headers named username and password???

    – miken32
    Nov 14 '18 at 21:32











  • Thanks for the tips. Erased style and use and still the same. Tried catching soupFault and it gives nothing usefull (just this: SoapClient->__call('Ping', Array) #1 {main}). Yes, if i dont send those headers gives authentication error.

    – Martin Chocho
    Nov 14 '18 at 22:02











  • You need to use the specific functions for SoapFault to get additional details, not just getMessage().

    – miken32
    Nov 14 '18 at 22:04













  • Can you share a link to the WSDL?

    – miken32
    Nov 14 '18 at 22:08














0












0








0








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);









share|improve this question
















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);






php soap soap-client






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 9 at 3:51









Cœur

17.7k9106145




17.7k9106145










asked Nov 14 '18 at 20:56









Martin ChochoMartin Chocho

456




456













  • First thing, get rid of style and use from your options, they should not be used in WSDL mode. Instead of catching Exception try catching SoapFault which can give you more error details: php.net/manual/en/soapfault.soapfault.php

    – miken32
    Nov 14 '18 at 21:31











  • And are you really supposed to pass HTTP headers named username and password???

    – miken32
    Nov 14 '18 at 21:32











  • Thanks for the tips. Erased style and use and still the same. Tried catching soupFault and it gives nothing usefull (just this: SoapClient->__call('Ping', Array) #1 {main}). Yes, if i dont send those headers gives authentication error.

    – Martin Chocho
    Nov 14 '18 at 22:02











  • You need to use the specific functions for SoapFault to get additional details, not just getMessage().

    – miken32
    Nov 14 '18 at 22:04













  • Can you share a link to the WSDL?

    – miken32
    Nov 14 '18 at 22:08



















  • First thing, get rid of style and use from your options, they should not be used in WSDL mode. Instead of catching Exception try catching SoapFault which can give you more error details: php.net/manual/en/soapfault.soapfault.php

    – miken32
    Nov 14 '18 at 21:31











  • And are you really supposed to pass HTTP headers named username and password???

    – miken32
    Nov 14 '18 at 21:32











  • Thanks for the tips. Erased style and use and still the same. Tried catching soupFault and it gives nothing usefull (just this: SoapClient->__call('Ping', Array) #1 {main}). Yes, if i dont send those headers gives authentication error.

    – Martin Chocho
    Nov 14 '18 at 22:02











  • You need to use the specific functions for SoapFault to get additional details, not just getMessage().

    – miken32
    Nov 14 '18 at 22:04













  • Can you share a link to the WSDL?

    – miken32
    Nov 14 '18 at 22:08

















First thing, get rid of style and use from your options, they should not be used in WSDL mode. Instead of catching Exception try catching SoapFault which can give you more error details: php.net/manual/en/soapfault.soapfault.php

– miken32
Nov 14 '18 at 21:31





First thing, get rid of style and use from your options, they should not be used in WSDL mode. Instead of catching Exception try catching SoapFault which can give you more error details: php.net/manual/en/soapfault.soapfault.php

– miken32
Nov 14 '18 at 21:31













And are you really supposed to pass HTTP headers named username and password???

– miken32
Nov 14 '18 at 21:32





And are you really supposed to pass HTTP headers named username and password???

– miken32
Nov 14 '18 at 21:32













Thanks for the tips. Erased style and use and still the same. Tried catching soupFault and it gives nothing usefull (just this: SoapClient->__call('Ping', Array) #1 {main}). Yes, if i dont send those headers gives authentication error.

– Martin Chocho
Nov 14 '18 at 22:02





Thanks for the tips. Erased style and use and still the same. Tried catching soupFault and it gives nothing usefull (just this: SoapClient->__call('Ping', Array) #1 {main}). Yes, if i dont send those headers gives authentication error.

– Martin Chocho
Nov 14 '18 at 22:02













You need to use the specific functions for SoapFault to get additional details, not just getMessage().

– miken32
Nov 14 '18 at 22:04







You need to use the specific functions for SoapFault to get additional details, not just getMessage().

– miken32
Nov 14 '18 at 22:04















Can you share a link to the WSDL?

– miken32
Nov 14 '18 at 22:08





Can you share a link to the WSDL?

– miken32
Nov 14 '18 at 22:08












1 Answer
1






active

oldest

votes


















1














Based on the wsdl, the ping method takes only 3 parameters.



class Ping {
/** @var BaseMessage */ public $message;
}
class BaseMessage {
/** @var string */ public $CommerceCode;
/** @var string */ public $TerminalCode;
/** @var int */ public $Timeout;
}


Also, you incorrectly set the authorization header. The correct way to do this:



$wsdl = "https://testing.memoryefactura.com/Memory.FEManager/WebService/CFEService.svc?wsdl";

$opts = [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false
],
'http' => [
'user_agent' => 'PHPSoapClient'
]
];

$params = [
'encoding' => 'UTF-8',
'verifypeer' => false,
'verifyhost' => false,
'soap_version' => SOAP_1_1,
'trace' => 1,
'exceptions' => 1,
'connection_timeout' => 180,
'stream_context' => stream_context_create($opts)
];

try {
$client = new SoapClient($wsdl, $params);

$nameSpace = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';

$soapUsername = new SoapVar(
'XXXXX',
XSD_STRING,
null,
$nameSpace,
null,
$nameSpace
);

$soapPassword = new SoapVar(
'XXXXX',
XSD_STRING,
null,
$nameSpace,
null,
$nameSpace
);

$auth = new stdClass();
$auth->Username = $soapUsername;
$auth->Password = $soapPassword;

$soapAuth = new SoapVar(
$auth,
SOAP_ENC_OBJECT,
null,
$nameSpace,
'UsernameToken',
$nameSpace
);

$token = new stdClass();
$token->UsernameToken = $soapAuth;

$soapToken = new SoapVar(
$token,
SOAP_ENC_OBJECT,
null,
$nameSpace,
'UsernameToken',
$nameSpace
);

$security = new SoapVar(
$soapToken,
SOAP_ENC_OBJECT,
null,
$nameSpace,
'Security',
$nameSpace
);

$header = new SoapHeader($nameSpace, 'Security', $security, true);

$client->__setSoapHeaders([$header]);

$parameters = array(
'CommerceCode' => 'XXXXX',
'TerminalCode' => 'XXXXX',
'Timeout' => 5000
);

$data = $client->Ping($parameters);
} catch (SoapFault $fault) {
echo "REQUEST:n" . $client->__getLastRequest();
die("nFaultcode: " . $fault->faultcode . "nFaultstring: " . $fault->faultstring);
} catch (Exception $e) {
die($e->getMessage());
}





share|improve this answer
























  • Thanks man! It throws Faultcode: a:InternalServiceFault Faultstring: Object reference not set to an instance of an object., any clue?

    – Martin Chocho
    Nov 15 '18 at 16:18











  • Don't worry, $data = $client->Ping(array('message' => $parameters)); solved it. Thanks a lot man, saved my neck!

    – Martin Chocho
    Nov 15 '18 at 16:29











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53308593%2fsoap-error-encoding-cannot-find-encoding%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Based on the wsdl, the ping method takes only 3 parameters.



class Ping {
/** @var BaseMessage */ public $message;
}
class BaseMessage {
/** @var string */ public $CommerceCode;
/** @var string */ public $TerminalCode;
/** @var int */ public $Timeout;
}


Also, you incorrectly set the authorization header. The correct way to do this:



$wsdl = "https://testing.memoryefactura.com/Memory.FEManager/WebService/CFEService.svc?wsdl";

$opts = [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false
],
'http' => [
'user_agent' => 'PHPSoapClient'
]
];

$params = [
'encoding' => 'UTF-8',
'verifypeer' => false,
'verifyhost' => false,
'soap_version' => SOAP_1_1,
'trace' => 1,
'exceptions' => 1,
'connection_timeout' => 180,
'stream_context' => stream_context_create($opts)
];

try {
$client = new SoapClient($wsdl, $params);

$nameSpace = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';

$soapUsername = new SoapVar(
'XXXXX',
XSD_STRING,
null,
$nameSpace,
null,
$nameSpace
);

$soapPassword = new SoapVar(
'XXXXX',
XSD_STRING,
null,
$nameSpace,
null,
$nameSpace
);

$auth = new stdClass();
$auth->Username = $soapUsername;
$auth->Password = $soapPassword;

$soapAuth = new SoapVar(
$auth,
SOAP_ENC_OBJECT,
null,
$nameSpace,
'UsernameToken',
$nameSpace
);

$token = new stdClass();
$token->UsernameToken = $soapAuth;

$soapToken = new SoapVar(
$token,
SOAP_ENC_OBJECT,
null,
$nameSpace,
'UsernameToken',
$nameSpace
);

$security = new SoapVar(
$soapToken,
SOAP_ENC_OBJECT,
null,
$nameSpace,
'Security',
$nameSpace
);

$header = new SoapHeader($nameSpace, 'Security', $security, true);

$client->__setSoapHeaders([$header]);

$parameters = array(
'CommerceCode' => 'XXXXX',
'TerminalCode' => 'XXXXX',
'Timeout' => 5000
);

$data = $client->Ping($parameters);
} catch (SoapFault $fault) {
echo "REQUEST:n" . $client->__getLastRequest();
die("nFaultcode: " . $fault->faultcode . "nFaultstring: " . $fault->faultstring);
} catch (Exception $e) {
die($e->getMessage());
}





share|improve this answer
























  • Thanks man! It throws Faultcode: a:InternalServiceFault Faultstring: Object reference not set to an instance of an object., any clue?

    – Martin Chocho
    Nov 15 '18 at 16:18











  • Don't worry, $data = $client->Ping(array('message' => $parameters)); solved it. Thanks a lot man, saved my neck!

    – Martin Chocho
    Nov 15 '18 at 16:29
















1














Based on the wsdl, the ping method takes only 3 parameters.



class Ping {
/** @var BaseMessage */ public $message;
}
class BaseMessage {
/** @var string */ public $CommerceCode;
/** @var string */ public $TerminalCode;
/** @var int */ public $Timeout;
}


Also, you incorrectly set the authorization header. The correct way to do this:



$wsdl = "https://testing.memoryefactura.com/Memory.FEManager/WebService/CFEService.svc?wsdl";

$opts = [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false
],
'http' => [
'user_agent' => 'PHPSoapClient'
]
];

$params = [
'encoding' => 'UTF-8',
'verifypeer' => false,
'verifyhost' => false,
'soap_version' => SOAP_1_1,
'trace' => 1,
'exceptions' => 1,
'connection_timeout' => 180,
'stream_context' => stream_context_create($opts)
];

try {
$client = new SoapClient($wsdl, $params);

$nameSpace = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';

$soapUsername = new SoapVar(
'XXXXX',
XSD_STRING,
null,
$nameSpace,
null,
$nameSpace
);

$soapPassword = new SoapVar(
'XXXXX',
XSD_STRING,
null,
$nameSpace,
null,
$nameSpace
);

$auth = new stdClass();
$auth->Username = $soapUsername;
$auth->Password = $soapPassword;

$soapAuth = new SoapVar(
$auth,
SOAP_ENC_OBJECT,
null,
$nameSpace,
'UsernameToken',
$nameSpace
);

$token = new stdClass();
$token->UsernameToken = $soapAuth;

$soapToken = new SoapVar(
$token,
SOAP_ENC_OBJECT,
null,
$nameSpace,
'UsernameToken',
$nameSpace
);

$security = new SoapVar(
$soapToken,
SOAP_ENC_OBJECT,
null,
$nameSpace,
'Security',
$nameSpace
);

$header = new SoapHeader($nameSpace, 'Security', $security, true);

$client->__setSoapHeaders([$header]);

$parameters = array(
'CommerceCode' => 'XXXXX',
'TerminalCode' => 'XXXXX',
'Timeout' => 5000
);

$data = $client->Ping($parameters);
} catch (SoapFault $fault) {
echo "REQUEST:n" . $client->__getLastRequest();
die("nFaultcode: " . $fault->faultcode . "nFaultstring: " . $fault->faultstring);
} catch (Exception $e) {
die($e->getMessage());
}





share|improve this answer
























  • Thanks man! It throws Faultcode: a:InternalServiceFault Faultstring: Object reference not set to an instance of an object., any clue?

    – Martin Chocho
    Nov 15 '18 at 16:18











  • Don't worry, $data = $client->Ping(array('message' => $parameters)); solved it. Thanks a lot man, saved my neck!

    – Martin Chocho
    Nov 15 '18 at 16:29














1












1








1







Based on the wsdl, the ping method takes only 3 parameters.



class Ping {
/** @var BaseMessage */ public $message;
}
class BaseMessage {
/** @var string */ public $CommerceCode;
/** @var string */ public $TerminalCode;
/** @var int */ public $Timeout;
}


Also, you incorrectly set the authorization header. The correct way to do this:



$wsdl = "https://testing.memoryefactura.com/Memory.FEManager/WebService/CFEService.svc?wsdl";

$opts = [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false
],
'http' => [
'user_agent' => 'PHPSoapClient'
]
];

$params = [
'encoding' => 'UTF-8',
'verifypeer' => false,
'verifyhost' => false,
'soap_version' => SOAP_1_1,
'trace' => 1,
'exceptions' => 1,
'connection_timeout' => 180,
'stream_context' => stream_context_create($opts)
];

try {
$client = new SoapClient($wsdl, $params);

$nameSpace = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';

$soapUsername = new SoapVar(
'XXXXX',
XSD_STRING,
null,
$nameSpace,
null,
$nameSpace
);

$soapPassword = new SoapVar(
'XXXXX',
XSD_STRING,
null,
$nameSpace,
null,
$nameSpace
);

$auth = new stdClass();
$auth->Username = $soapUsername;
$auth->Password = $soapPassword;

$soapAuth = new SoapVar(
$auth,
SOAP_ENC_OBJECT,
null,
$nameSpace,
'UsernameToken',
$nameSpace
);

$token = new stdClass();
$token->UsernameToken = $soapAuth;

$soapToken = new SoapVar(
$token,
SOAP_ENC_OBJECT,
null,
$nameSpace,
'UsernameToken',
$nameSpace
);

$security = new SoapVar(
$soapToken,
SOAP_ENC_OBJECT,
null,
$nameSpace,
'Security',
$nameSpace
);

$header = new SoapHeader($nameSpace, 'Security', $security, true);

$client->__setSoapHeaders([$header]);

$parameters = array(
'CommerceCode' => 'XXXXX',
'TerminalCode' => 'XXXXX',
'Timeout' => 5000
);

$data = $client->Ping($parameters);
} catch (SoapFault $fault) {
echo "REQUEST:n" . $client->__getLastRequest();
die("nFaultcode: " . $fault->faultcode . "nFaultstring: " . $fault->faultstring);
} catch (Exception $e) {
die($e->getMessage());
}





share|improve this answer













Based on the wsdl, the ping method takes only 3 parameters.



class Ping {
/** @var BaseMessage */ public $message;
}
class BaseMessage {
/** @var string */ public $CommerceCode;
/** @var string */ public $TerminalCode;
/** @var int */ public $Timeout;
}


Also, you incorrectly set the authorization header. The correct way to do this:



$wsdl = "https://testing.memoryefactura.com/Memory.FEManager/WebService/CFEService.svc?wsdl";

$opts = [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false
],
'http' => [
'user_agent' => 'PHPSoapClient'
]
];

$params = [
'encoding' => 'UTF-8',
'verifypeer' => false,
'verifyhost' => false,
'soap_version' => SOAP_1_1,
'trace' => 1,
'exceptions' => 1,
'connection_timeout' => 180,
'stream_context' => stream_context_create($opts)
];

try {
$client = new SoapClient($wsdl, $params);

$nameSpace = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';

$soapUsername = new SoapVar(
'XXXXX',
XSD_STRING,
null,
$nameSpace,
null,
$nameSpace
);

$soapPassword = new SoapVar(
'XXXXX',
XSD_STRING,
null,
$nameSpace,
null,
$nameSpace
);

$auth = new stdClass();
$auth->Username = $soapUsername;
$auth->Password = $soapPassword;

$soapAuth = new SoapVar(
$auth,
SOAP_ENC_OBJECT,
null,
$nameSpace,
'UsernameToken',
$nameSpace
);

$token = new stdClass();
$token->UsernameToken = $soapAuth;

$soapToken = new SoapVar(
$token,
SOAP_ENC_OBJECT,
null,
$nameSpace,
'UsernameToken',
$nameSpace
);

$security = new SoapVar(
$soapToken,
SOAP_ENC_OBJECT,
null,
$nameSpace,
'Security',
$nameSpace
);

$header = new SoapHeader($nameSpace, 'Security', $security, true);

$client->__setSoapHeaders([$header]);

$parameters = array(
'CommerceCode' => 'XXXXX',
'TerminalCode' => 'XXXXX',
'Timeout' => 5000
);

$data = $client->Ping($parameters);
} catch (SoapFault $fault) {
echo "REQUEST:n" . $client->__getLastRequest();
die("nFaultcode: " . $fault->faultcode . "nFaultstring: " . $fault->faultstring);
} catch (Exception $e) {
die($e->getMessage());
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 15 '18 at 8:57









SorboSorbo

30914




30914













  • Thanks man! It throws Faultcode: a:InternalServiceFault Faultstring: Object reference not set to an instance of an object., any clue?

    – Martin Chocho
    Nov 15 '18 at 16:18











  • Don't worry, $data = $client->Ping(array('message' => $parameters)); solved it. Thanks a lot man, saved my neck!

    – Martin Chocho
    Nov 15 '18 at 16:29



















  • Thanks man! It throws Faultcode: a:InternalServiceFault Faultstring: Object reference not set to an instance of an object., any clue?

    – Martin Chocho
    Nov 15 '18 at 16:18











  • Don't worry, $data = $client->Ping(array('message' => $parameters)); solved it. Thanks a lot man, saved my neck!

    – Martin Chocho
    Nov 15 '18 at 16:29

















Thanks man! It throws Faultcode: a:InternalServiceFault Faultstring: Object reference not set to an instance of an object., any clue?

– Martin Chocho
Nov 15 '18 at 16:18





Thanks man! It throws Faultcode: a:InternalServiceFault Faultstring: Object reference not set to an instance of an object., any clue?

– Martin Chocho
Nov 15 '18 at 16:18













Don't worry, $data = $client->Ping(array('message' => $parameters)); solved it. Thanks a lot man, saved my neck!

– Martin Chocho
Nov 15 '18 at 16:29





Don't worry, $data = $client->Ping(array('message' => $parameters)); solved it. Thanks a lot man, saved my neck!

– Martin Chocho
Nov 15 '18 at 16:29


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53308593%2fsoap-error-encoding-cannot-find-encoding%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Xamarin.form Move up view when keyboard appear

JBPM : POST request for execute process go wrong