Home > Blockchain >  Fatal error: Uncaught Error: Class "SoapClient" not found
Fatal error: Uncaught Error: Class "SoapClient" not found

Time:08-28

Hello I am trying to build with the UPS API for CANADA. The documentation is pretty rugged and i am having a hard time understanding it....

My code is as follows:

<?php

//Configuration
$outputFileName = "XOLTResult.xml";
$access = "XXXX";
$userid = "XXXX";
$passwd = 'XXXX';
$wsdl = file_get_contents("RateWS.WSDL");
$operation = "ProcessRate";
$endpointurl = 'https://wwwcie.ups.com/webservices/FreightRate';

//create soap request
$option['RequestOption'] = 'RateChecking Option';
$request['Request'] = $option;
$shipfrom['Name'] = 'Good Incorporation';
$addressFrom['AddressLine'] = '2010 WARSAW ROAD';
$addressFrom['City'] = 'Roswell';
$addressFrom['StateProvinceCode'] = 'GA';
$addressFrom['PostalCode'] = '30076';
$addressFrom['CountryCode'] = 'US';
$shipfrom['Address'] = $addressFrom;
$request['ShipFrom'] = $shipfrom;

$shipto['Name'] = 'Sony Company Incorporation';
$addressTo['AddressLine'] = '2311 YORK ROAD';
$addressTo['City'] = 'TIMONIUM';
$addressTo['StateProvinceCode'] = 'MD';
$addressTo['PostalCode'] = '21093';
$addressTo['CountryCode'] = 'US';
$shipto['Address'] = $addressTo;
$request['ShipTo'] = $shipto;

$payer['Name'] = 'Payer inc';
$addressPayer['AddressLine'] = '435 SOUTH STREET';
$addressPayer['City'] = 'RIS TOWNSHIP';
$addressPayer['StateProvinceCode'] = 'NJ';
$addressPayer['PostalCode'] = '07960';
$addressPayer['CountryCode'] = 'US';
$payer['Address'] = $addressPayer;
$shipmentbillingoption['Code'] = '10';
$shipmentbillingoption['Description'] = 'PREPAID';
$paymentinformation['Payer'] = $payer;
$paymentinformation['ShipmentBillingOption'] = $shipmentbillingoption;
$request['PaymentInformation'] = $paymentinformation;

$service['Code'] = '02';
$service['Description'] = '2nd Day Air';
$request['Service'] = $service;

$commodity['CommodityID'] = '';
$commodity['Description'] = 'No Description';
$commodity['Weight'] = array
(
   'UnitOfMeasurement' => array
   (
       'Code' => 'LBS',
       'Description' => 'Pounds'
   ),
   'Value' => '11'
);
$commodity['Dimensions'] = array
(
    'UnitOfMeasurement' => array
    (
        'Code' => 'IN',
        'Description' => 'Inches'
    ),
    'Length' => '23',
    'Width' => '17',
    'Height' => '45'
);
$commodity['NumberOfPieces'] = '1';
$commodity['DangerousGoodsIndicator'] = '';
$commodity['CommodityValue'] = array
(
     'CurrencyCode' => 'CAD',
     'MonetaryValue' => '500'
);
$request['Commodity'] = $commodity;

$shipmentserviceoptions['PickupOptions'] = array
    (
          'HolidayPickupIndicator' => '',
        'InsidePickupIndicator' => '',
      'ResidentialPickupIndicator' => '',
      'WeekendPickupIndicator' => '',
      'LiftGateRequiredIndicator' => ''
  );

try
{

  $mode = array
  (
       'soap_version' => 'SOAP_1_1',  // use soap 1.1 client
       'trace' => 1
  );

  // initialize soap client
  $client = new SoapClient($wsdl , $mode);

  //set endpoint url
  $client->__setLocation($endpointurl);


  //create soap header
  $usernameToken['Username'] = $userid;
  $usernameToken['Password'] = $passwd;
  $serviceAccessLicense['AccessLicenseNumber'] = $access;
  $upss['UsernameToken'] = $usernameToken;
  $upss['ServiceAccessToken'] = $serviceAccessLicense;

  $header = new SoapHeader('http://www.ups.com/XMLSchema/XOLTWS/UPSS/v1.0','UPSSecurity',$upss);
  $client->__setSoapHeaders($header);


  //get response
  $resp = $client->__soapCall($operation ,array(processFreightRate()));

  //get status
  echo "Response Status: " . $resp->Response->ResponseStatus->Description ."\n";

  //save soap request and response to file
  $fw = fopen($outputFileName , 'w');
  fwrite($fw , "Request: \n" . $client->__getLastRequest() . "\n");
  fwrite($fw , "Response: \n" . $client->__getLastResponse() . "\n");
  fclose($fw);

}
catch(Exception $ex)
{
  print_r ($ex);
}
?>

and i am getting the following error:

Fatal error: Uncaught Error: Class "SoapClient" not found in C:\xampp\htdocs\upsapi\RatingPACKAGE\PACKAGEWebServices\CodeSamples\Rate\PHP\SoapRateClient.php:121 Stack trace: #0 {main} thrown in C:\xampp\htdocs\upsapi\RatingPACKAGE\PACKAGEWebServices\CodeSamples\Rate\PHP\SoapRateClient.php on line 121

Any help would be greatly appreciated.

It appears soap client was not on server but I believe that is resolved as I am now getting

SoapFault Object ( [message:protected] => SOAP-ERROR: Parsing WSDL: Couldn't load from ' ' : failed to load external entity " " [string:Exception:private] => [code:protected] => 0 [file:protected] => C:\xampp\htdocs\upsapi\ShippingPACKAGE\PACKAGEWebServices\CodeSamples\Ship\PHP\SoapShipClient.php [line:protected] => 185 [trace:Exception:private] => Array ( [0] => Array ( [file] => C:\xampp\htdocs\upsapi\ShippingPACKAGE\PACKAGEWebServices\CodeSamples\Ship\PHP\SoapShipClient.php [line] => 185 [function] => __construct [class] => SoapClient [type] => -> [args] => Array ( [0] => [1] => Array ( [soap_version] => SOAP_1_1 [trace] => 1 ) ) ) ) [previous:Exception:private] => [faultstring] => SOAP-ERROR: Parsing WSDL: Couldn't load from ' ' : failed to load external entity " " [faultcode] => WSDL [faultcodens] => [faultactor] => [detail] => [_name] => [headerfault] => )

CodePudding user response:

In XAMPP Control Panel

  1. Stop Apache Server

  2. Click on Config next to Apache

  3. From dropdown select PHP (php.ini)

  4. Ctrl F to find ;extension=soap remove ; from the line.

  5. Ctrl S to save the file.

  6. Start Apache again.

    extension=soap

  • Related