PHP SOAP Client - Wrong Version (VersionMismatch) on DHL API

Tuesday, November 3, 2015

DHL will not give more support: Therefore I'll ask you, to solve my issue.
I write an PHP Soap Client to create packet labels. I use the API, which is described on entwickler.dhl.com.



This is my code:



// Disable WSDL Cache
ini_set('soap.wsdl_cache_enabled', 0);
ini_set('soap.wsdl_cache_ttl', 0);

/* WSDL */
$wsdl = "https://cig.dhl.de/cig-wsdls/com/dpdhl/wsdl/geschaeftskundenversand-api/1.0/geschaeftskundenversand-api-1.0.wsdl";

$param = new SoapVar(array('user' => 'geschaeftskunden_api', 'signature' => 'Dhl_ep_test1', 'type' => 0), SOAP_ENC_OBJECT);
$header = new SoapHeader('https://cig.dhl.de/services/sandbox/soap', 'Authentication', $param, false);

$options = array(
'location' => 'http://dhl.de/webservice/cisbase',
'trace' => true,
'exception' => true,
'encoding' => 'utf-8',
'soap_version' => SOAP_1_2);

$soap_client = new SoapClient($wsdl, $options);
$soap_client->__setSoapHeaders(array($header));

$requestArray = array(
'Version' => array(
'majorRelease' => '1',
'minorRelease' => '0'
),
'ShipmentOrder' => array(
'SequenceNumber' => '1',
'Shipment' => array(
'ShipmentDetails' => array(
'ProductCode' => 'EPN',
'ShipmentDate' => date("Y-m-d", strtotime("tomorrow")),
'EKP' => '5000000000',
'Account' => array(
'accountNumberExpress' => ''
),
'Dutiable' => '',
'DescriptionOfContent' => '',
'Attendance' => array(
'partnerID' => '01',
),
'CustomerReference' => 'Kundennummer 1234567',
'ShipmentItem' => array(
'WeightInKG' => '10',
'LengthInCM' => '50',
'WidthInCM' => '30',
'HeightInCM' => '15',
'PackageType' => 'PK',
),
),
'Shipper' => array(
'Company' => array(
'Company' => array(
'name1' => 'Muster Company',
),
),
'Address' => array(
'streetName' => 'Leipziger Stra?e',
'streetNumber' => '47',
'Zip' => array(
'germany' => '10117',
),
'city' => 'Berlin',
'Origin' => array(
'countryISOCode' => 'DE',
),
),
'Communication' => array(
'email' => 'max@muster.de',
'contactPerson' => 'Max Muster',
),
),
'Receiver' => array(
'Company' => array(
'Person' => array(
'firstname' => 'Markus',
'lastname' => 'Meier',
),
),
'Address' => array(
'streetName' => 'Marktplatz',
'streetNumber' => '1',
'Zip' => array(
'other' => '70173',
),
'city' => 'Stuttgart',
'Origin' => array(
'countryISOCode' => 'DE',
),
),
'Communication' => array(
'phone' => '0049-30-763291',
),
),
),
),
);

try {
$soap_client->createShipmentDD($requestArray);
} catch (Exception $exception) {
echo "<h2>Fehler</h2>";
echo "<pre>" . print_r($exception, true) . "</pre>";
}


If I run the script above I get an exception:



[faultstring] => Wrong Version
[faultcode] => VersionMismatch
[faultcodens] => http://www.w3.org/2003/05/soap-envelope


The XML of the request is nearly an copy of the demo code of DHL.



Feedback from DHL:



You're using an php soap client. Please check your settings, because default is .1, therefore you got this error. DHL require 1.2. You're sending the envelope (http://www.w3.org/2003/05/soap-envelope)



It does not matter wether I send SOAP_1_2 or SOAP_1_1.



UPDATE1: I tried also SoapUI, but got also errors:



HTTP/1.1 401 Authorization Required
Date: Tue, 03 Nov 2015 09:01:55 GMT
WWW-Authenticate: Basic realm="CIG Sandbox Services"
Content-Length: 462
Connection: close
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>401 Authorization Required</title>
</head><body>
<h1>Authorization Required</h1>
<p>This server could not verify that you
are authorized to access the document
requested. Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn't understand how to supply
the credentials required.</p>
<hr>
<address>Apache Server at cig.dhl.de Port 443</address>
</body></html>


So, do you have an idea whats wrong in my code?



========= UPDATE 2 ========= SOLUTION =========
It was he wrong endpoint and missing header parameters.
Everything is working now.

0 comments:

Post a Comment