Samuel Zeh
Samuel Zeh

Reputation: 21

SOAP call with PHP WSDL and HTTP Authentication

I am a beginner in programming and have a problem with a soap call.

I would like to get 64based shipment labels from DHL. I usually work with Rest but DHL do only has SOAP in Germany.

I get this error:

SOAP-ENV:ServerUncaught SoapFault exception: [soap:Receiver] UNKNOWN_ERROR in /homepages/12/d573220848/htdocs/beta/dhl/index.php:90 Stack trace: #0 /homepages/12/d573220848/htdocs/beta/dhl/index.php(90): SoapClient->__soapCall('createShipmentO...', Array, Array) #1 {main} thrown

authentication works I think

Here is the php code from me as client

$wsdl = 'https://cig.dhl.de/cig-wsdls/com/dpdhl/wsdl/geschaeftskundenversand-api/2.2/geschaeftskundenversand-api-2.2.wsdl';
  $params = array(
      'location' => "https://cig.dhl.de/services/sandbox/soap", 
      'uri' => "https://",
      'login' => "*userid*",
      'password' => "*secret_password*",
      'soap_version' => SOAP_1_2,
      'exceptions' => True,
      'trace' => 1
  );

  $client = new SoapClient($wsdl, $params);
  $header = new SoapHeader("https://cig.dhl.de/services/sandbox/soap", "authentication", "Basic [EDITED]"); 
  use_soap_error_handler(true);
  //Funktionen und Typen anfragen
  echo '<h3>Funktionen</h3>';
  $functions = $client->__getFunctions();
  foreach($functions as $d){
      echo "<br>".$d;
  }
  echo '<br><h3>Types</h3>';
  $types = $client->__getTypes();
  foreach($types as $t){
      echo "<br>".$t;
  }
  echo '<br><br>';


  $request = array(
      'CreateShipmentOrderRequest' => "1",
          'Version' => array(
          'majorRelease' => "2",
          'minorRelease' => "0"),
      'ShipmentOrder' => array(
      'SequenceNumber' => "01",
          'Shipment' => array(
          'ShipmentDetails' => array(
          'product' => "V01PAK",
          'accountNumber' => "22222222220101")))

  );

  //RESPONSE
  $response = $client ->__soapCall("createShipmentOrder", $request, $params);
  var_dump($response);
  echo '<br><br>';

I get all the types and functions, but no request. This is from documentary of dhl:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
               xmlns:cis="http://dhl.de/webservice/cisbase"
               xmlns:bcs="http://dhl.de/webservices/businesscustomershipping"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soap:Header>
        <cis:Authentification>
            <cis:user>2222222222_01</cis:user>
            <cis:signature>pass</cis:signature>
        </cis:Authentification>
    </soap:Header>
    <soap:Body>
    ...
    </soap:Body>
</soap:Envelope>

Die Abrechnungsnummern müssen zusammen mit dem Produkt im SOAP-Body im Type "Shipment Details" eingetragen werden:

</soap:Header>
    <soap:Body>
        <bcs:CreateShipmentOrderRequest>
            <cis:Version>
                <cis:majorRelease>2</cis:majorRelease>
                <cis:minorRelease>0</cis:minorRelease>
            </cis:Version>
            <ShipmentOrder>
                <SequenceNumber>01</SequenceNumber>
                <Shipment>
                    <ShipmentDetails>
                        <product>V01PAK</product>
                        <cis:accountNumber>22222222220101</cis:accountNumber>

What can I do to bring it to work?

Upvotes: 2

Views: 7715

Answers (1)

I used part from your code, part from example DHL and have result . I hope this help you . I too have task of development SOAP client for DHL API and if you have more example or question about this I will be thankful. Sample data getVersion request http://prntscr.com/i5jepf

$wsdl =  'https://cig.dhl.de/cig-wsdls/com/dpdhl/wsdl/geschaeftskundenversand-api/2.2/geschaeftskundenversand-api-2.2.wsdl';   
$sandbox = "https://cig.dhl.de/services/sandbox/soap";  
$user = "******";
$password = "*******";  
$options = array(
  'location' => $sandbox, 
  'uri' => "",
  'login' => $user,
  'password' => $password,
  'soap_version' => SOAP_1_1,
  'exceptions' => false,
  'trace' => 1
);  
$client = new SoapClient($wsdl,$options);   
$request ='Sample data getVersion install here';
$result = $client->__doRequest($request,$sandbox, 'getVersion',1);
if (is_soap_fault($result)) {
   trigger_error("Error SOAP: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
}   
var_dump($result);  
string(512) " 2 2 8 "

Upvotes: 1

Related Questions