petroni
petroni

Reputation: 776

Version Mismatch in PHP SOAP Call

I'm trying to make a soap call to a server with as little code as possible. But I'm alreaty having issues authenticating myself (No headers neccessary for that call). This is the code I have:

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
header('Content-Type: text/html; charset=utf-8');

$data = array('Username' => 'someusername', 'Userpass' => 'somepass');

try
{
   $client = new SoapClient(null, array( 
       "location" => "http://relaxdays.plentymarkets-x1.com/plenty/api/soap/version115/?xml",
       "uri" => "http://relaxdays.plentymarkets-x1.com/plenty/api/soap/version115/",
       "trace" => true,
       "soap_version" => SOAP_1_1,
       "exceptions" => false
    ));
   $response = $client->__soapCall("PlentySoapRequest_GetAuthentificationToken", $data);
}

catch (Exception $e)
{
   echo "Error!";
   echo $e -> getMessage();
   echo '<br/><br/>Last response:<button type="button" onclick="if(document.getElementById(\'spoiler1\').style.display==\'none\') {document.getElementById(\'spoiler1\') .style.display=\'\'}else{document.getElementById(\'spoiler1\') .style.display=\'none\'}">Show/Hide</button><div id="spoiler1" style="display:none; font-family:monospace;">'. htmlspecialchars($client->__getLastResponse()).'</div>';
}

echo '<br/><br/>Last request:<button type="button" onclick="if(document.getElementById(\'spoiler2\').style.display==\'none\') {document.getElementById(\'spoiler2\') .style.display=\'\'}else{document.getElementById(\'spoiler2\') .style.display=\'none\'}">Show/Hide</button><div id="spoiler2" style="display:none; font-family:monospace;">'. htmlspecialchars($client->__getLastRequest()).'</div>';  

echo '<br/><br/>Response:<button type="button" onclick="if(document.getElementById(\'spoiler3\').style.display==\'none\') {document.getElementById(\'spoiler3\') .style.display=\'\'}else{document.getElementById(\'spoiler3\') .style.display=\'none\'}">Show/Hide</button><div id="spoiler3" style="display:none; font-family:monospace;">'. htmlspecialchars($response).'</div>';    
?>

However, regardless of what I try, it doesn't seem to work. The furthest I've come is this error:

SoapFault exception: [VersionMismatch] Wrong Version in /var/www/htdocs/plentyimport/tester.php:18 
Stack trace: #0 /var/www/htdocs/plentyimport/tester.php(18): SoapClient->__soapCall('PlentySoapReque...', Array) #1 {main}

I've already tried using "soap_version" => SOAP_1_2, or switching the Soap-URL to different versions (eg. /version112/) but the error just does not want to go away.

Any help would be appreciated.

Thank you very much

virhonestum

Upvotes: 1

Views: 1746

Answers (1)

Martin Janeček
Martin Janeček

Reputation: 585

You have to pass the definition of SOAP as first parameter, like this:

$client = new SoapClient('http://relaxdays.plentymarkets-x1.com/plenty/api/soap/version115/?xml');

I have stripped other arguments as those are not required for making this work.

The call should be made to operation, in this case like this:

$response = $client->__soapCall("GetAuthentificationToken", $data);

An finally, the data should contain structure PlentySoapRequest_GetAuthentificationToken, like this:

$data = [
  'PlentySoapRequest_GetAuthentificationToken' => [
    'Username' =>  'someusername',
    'Userpass' =>  'somepassword'
  ]
];

Note: I'm not posting this as complete answer. I don't know SOAP and can't explain what was wrong and how I fixed it, only posting this to help author get out of this phase.

Upvotes: 1

Related Questions