I am using ValidateShipment.php from purolator.com . I included all the wsdl files and included product key and password . But still getting error(s).
soap is already enabled.
you can see error here
Warning: Creating default object from empty value in /home/bandito/public_html/ValidateShipment.php on line 64
Warning: Creating default object from empty value in /home/bandito/public_html/ValidateShipment.php on line 71
Warning: Creating default object from empty value in /home/bandito/public_html/ValidateShipment.php on line 75
Warning: Creating default object from empty value in /home/bandito/public_html/ValidateShipment.php on line 82
Warning: Creating default object from empty value in /home/bandito/public_html/ValidateShipment.php on line 90
Warning: Creating default object from empty value in /home/bandito/public_html/ValidateShipment.php on line 95
Warning: Creating default object from empty value in /home/bandito/public_html/ValidateShipment.php on line 99
Warning: Creating default object from empty value in /home/bandito/public_html/ValidateShipment.php on line 101
Warning: Creating default object from empty value in /home/bandito/public_html/ValidateShipment.php on line 106
Fatal error: Uncaught SoapFault exception: [HTTP] Unauthorized in /home/bandito/public_html/ValidateShipment.php:110 Stack trace: #0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'https://webserv...', 'http://purolato...', 1, 0) #1 /home/bandito/public_html/ValidateShipment.php(110): SoapClient->__call('ValidateShipmen...', Array) #2 /home/bandito/public_html/ValidateShipment.php(110): SoapClient->ValidateShipment(Object(stdClass)) #3 {main} thrown in /home/bandito/public_html/ValidateShipment.php on line 110
and here is my php code-:
define("PRODUCTION_KEY", "**********************");
define("PRODUCTION_PASS", "***********");
define("BILLING_ACCOUNT", "**********");
define("REGISTERED_ACCOUNT", "**********");
function createPWSSOAPClient()
{
$client = new SoapClient( "wsdl/ShippingService.wsdl",
array (
'trace' => true,
'location' => "https://webservices.purolator.com/PWS/V1/Shipping/ShippingService.asmx",
'uri' => "http://purolator.com/pws/datatypes/v1",
'login' => PRODUCTION_KEY,
'password' => PRODUCTION_PASS
)
);
//Define the SOAP Envelope Headers
$headers[] = new SoapHeader ( 'http://purolator.com/pws/datatypes/v1',
'RequestContext',
array (
'Version' => '1.4',
'Language' => 'en',
'GroupID' => 'xxx',
'RequestReference' => 'Rating Example'
)
);
//Apply the SOAP Header to your client
$client->__setSoapHeaders($headers);
return $client;
}
/*********************************************************************************
Validate Shipment Example(s)
EXAMPLE 01:
1 piece shipment, 10lbs, Purolator Express Service on a Thermal 4x6 Label
*********************************************************************************/
//Create a SOAP Client for Example 01
$client = createPWSSOAPClient();
//Populate the Origin Information
$request->Shipment->SenderInformation->Address->Name = "Aaron Summer";
$request->Shipment->SenderInformation->Address->StreetNumber = "1234";
$request->Shipment->SenderInformation->Address->StreetName = "Main Street";
$request->Shipment->SenderInformation->Address->City = "Mississauga";
$request->Shipment->SenderInformation->Address->Province = "ON";
$request->Shipment->SenderInformation->Address->Country = "CA";
$request->Shipment->SenderInformation->Address->PostalCode = "L4W5M8";
$request->Shipment->SenderInformation->Address->PhoneNumber->CountryCode = "1";
$request->Shipment->SenderInformation->Address->PhoneNumber->AreaCode = "905";
$request->Shipment->SenderInformation->Address->PhoneNumber->Phone = "5555555";
//Populate the Desination Information
$request->Shipment->ReceiverInformation->Address->Name = "Aaron Summer";
$request->Shipment->ReceiverInformation->Address->StreetNumber = "2245";
$request->Shipment->ReceiverInformation->Address->StreetName = "Douglas Road";
$request->Shipment->ReceiverInformation->Address->City = "Burnaby";
$request->Shipment->ReceiverInformation->Address->Province = "BC";
request->Shipment->ReceiverInformation->Address->Country = "CA";
$request->Shipment->ReceiverInformation->Address->PostalCode = "V5C5A9";
$request->Shipment->ReceiverInformation->Address->PhoneNumber->CountryCode = "1";
$request->Shipment->ReceiverInformation->Address->PhoneNumber->AreaCode = "604";
$request->Shipment->ReceiverInformation->Address->PhoneNumber->Phone = "2982181";
//Future Dated Shipments - YYYY-MM-DD format
$request->Shipment->ShipmentDate = "YOUR_SHIPMENT_DATE_HERE";
//Populate the Package Information
$request->Shipment->PackageInformation->TotalWeight->Value = "10";
$request->Shipment->PackageInformation->TotalWeight->WeightUnit = "lb";
$request->Shipment->PackageInformation->TotalPieces = "1";
$request->Shipment->PackageInformation->ServiceID = "PurolatorExpress";
//Populate the Payment Information
$request->Shipment->PaymentInformation->PaymentType = "Sender";
$request->Shipment->PaymentInformation->BillingAccountNumber = BILLING_ACCOUNT;
$request->Shipment->PaymentInformation->RegisteredAccountNumber = REGISTERED_ACCOUNT;
//Populate the Pickup Information
$request->Shipment->PickupInformation->PickupType = "DropOff";
//Shipment Reference
$request->Shipment->TrackingReferenceInformation->Reference1 = "Reference For Shipment";
//Define the Shipment Document Type
$request->PrinterType = "Thermal";
//Define OptionsInformation
$request->OptionsInformation->Options->OptionIDValuePair->ID = "residentialsignaturedomestic";
$request->OptionsInformation->Options->OptionIDValuePair->Value = "true";
//Execute the request and capture the response
$response = $client->ValidateShipment($request);
print_r($response);
The $request class isn't declared. PHP is guessing it's an object and declaring it.
Try:
$request = new stdClass;
$request->Shipment = new stdClass;
$request->Shipment->ReceiverInformatio = new stdClass;
etc.
Place before the $request list starts.
//Populate the Origin Information
$request->Shipment->SenderInformation->Address->Name = "Aaron Summer";
Replace this line
$request->Shipment->SenderInformation->Address->Name = "Aaron Summer";
with
#$request->Shipment->SenderInformation->Address->Name = "Aaron Summer";
Related
I have a bit of code that takes in XML and attempts to validate it. However, I keep getting an error
Error type: 8192
Error message: Assigning the return value of new by reference is deprecated
From looking around it seems like there must be underlying code that uses assignment by reference e.g $foo = & ... I tried to change my code e.g. to use the technique used here but to no avail.
$version = $_POST["xacmlversion"];
$source = $_POST["policy"];
if (get_magic_quotes_gpc()){
$source = stripslashes($source);
}
$xdoc = new DomDocument();
if ($version == 2){
$xmlschema = 'xacml/xacml2.xsd';
} else {
$xmlschema = 'xacml/xacml3.xsd';
$version = 3;
}
$xdoc->LoadXML($source);
//Validate the XML file against the schema
$valid = $xdoc->schemaValidate($xmlschema);
So where's the blooper?
UPDATE
Here is the root cause
Array
(
[type] => 8192
[message] => Assigning the return value of new by reference is deprecated
[file] => /home/www/wp-content/plugins/exec-php/includes/ajax.php
[line] => 64
)
I'm getting this error when I try and generate an excel document anyone know where this error is coming from?
Fatal error: Uncaught Error: Call to undefined method
PHPExcel::sheetNameExists() in
/public_html/docs/PHP/PHPExcel/Worksheet.php:835 Stack
trace: #0
/public_html/docs/PHP/PHPExcel/Worksheet.php(337):
PHPExcel_Worksheet->setTitle('Worksheet', false) #1
/public_html/docs/PHP/PHPExcel.php(108):
PHPExcel_Worksheet->__construct(Object(PHPExcel)) #2
/public_html/docs/SendDocument.php(33):
PHPExcel->__construct() #3 {main} thrown in
/public_html/docs/PHP/PHPExcel/Worksheet.php on line 835
<?php
//Excel Data
$Spo = $_SESSION["spo"];
$Cont = $_SESSION["contractNum"];
$Site = $_SESSION["siteMan"];
$Job = $_SESSION["jtd"];
$ObBrief = $_SESSION["ob_Des"];
$ObAgreed = $_SESSION["ob_Act"];
$ObDate = $_SESSION["date1"];
$GoBrief = $_SESSION["good_Des"];
$GoAgreed = $_SESSION["good_Act"];
$GoDate = $_SESSION["date2"];
$FeBrief = $_SESSION["fe_Des"];
$FeAgreed = $_SESSION["fe_Act"];
$FeDate = $_SESSION["date3"];
$Q1 = '';
$Q2 = '';
$Q3 = '';
$Q4 = '';
$Q5 = '';
$Q6 = '';
$Q7 = '';
$Q8 = '';
$Q9 = '';
$Q10 = '';
$Add = $_SESSION["addCom"];
$Name = $_SESSION["name"];
$Title = $_SESSION["title"];
$Date = $_SESSION["date4"];
Include_once 'PHP/PHPExcel.php';
$objPHPExcel = new PHPExcel();
$activeSheet = $objPHPExcel->getActiveSheet();
$objPHPExcel->getActiveSheet()->setTitle('Senior Managers Site Tour');
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(5);
$styleArray = array(
'borders' => array(
'allborders' => array(
'style' => PHPExcel_Style_Border::BORDER_THIN
)
)
);
//Set Up
$activeSheet->setCellValue('E1','Senior Managers Site Tour');
$objPHPExcel->getActiveSheet()->getStyle('A1:N70')->applyFromArray($styleArray);
$objPHPExcel->getActiveSheet()->mergeCells('A1:A70');
$objPHPExcel->getActiveSheet()->mergeCells('N1:N70');
$objPHPExcel->getActiveSheet()->getStyle('B6:M68')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_TOP);
$titleArray = array(
'font' => array(
'bold' => true,
'size' => 32,
));
$styleTitleAlign = array(
'alignment' => array(
'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
)
);
//Title
$objPHPExcel->getActiveSheet()->mergeCells('B1:D4');
$objPHPExcel->getActiveSheet()->mergeCells('E1:M4');
$objPHPExcel->getActiveSheet()->mergeCells('B5:M5');
$objPHPExcel->getActiveSheet()->getStyle('E1')->applyFromArray($titleArray);
$objPHPExcel->getActiveSheet()->getStyle('E1')->applyFromArray($styleTitleAlign);
//Basic Information
$objPHPExcel->getActiveSheet()->mergeCells('B6:D6');
$objPHPExcel->getActiveSheet()->mergeCells('E6:G6');
$objPHPExcel->getActiveSheet()->mergeCells('H6:J6');
$objPHPExcel->getActiveSheet()->mergeCells('K6:M6');
$objPHPExcel->getActiveSheet()->mergeCells('B7:D7');
$objPHPExcel->getActiveSheet()->mergeCells('E7:M7');
$objPHPExcel->getActiveSheet()->mergeCells('B8:D8');
$objPHPExcel->getActiveSheet()->mergeCells('E8:M8');
$objPHPExcel->getActiveSheet()->mergeCells('B9:M10');
$activeSheet->setCellValue('B6','Site / Project / Object:');
$activeSheet->setCellValue('E6', $Spo);
$activeSheet->setCellValue('H6','Contract Number:');
$activeSheet->setCellValue('K6',$Cont);
$activeSheet->setCellValue('B7','Site Manager:');
$activeSheet->setCellValue('E7',$Site);
$activeSheet->setCellValue('B8','Job / Task Description:');
$activeSheet->setCellValue('E8',$Job);
//Observation
$objPHPExcel->getActiveSheet()->mergeCells('B11:M11');
$objPHPExcel->getActiveSheet()->mergeCells('B12:E12');
$objPHPExcel->getActiveSheet()->mergeCells('F12:I12');
$objPHPExcel->getActiveSheet()->mergeCells('J12:M12');
$objPHPExcel->getActiveSheet()->mergeCells('B13:E17');
$objPHPExcel->getActiveSheet()->mergeCells('F13:I17');
$objPHPExcel->getActiveSheet()->mergeCells('J13:M17');
$objPHPExcel->getActiveSheet()->mergeCells('B18:M19');
$activeSheet->setCellValue('B11','OBSERVATION (areas where improvement can be made).');
$activeSheet->setCellValue('B12','Brief Description:');
$activeSheet->setCellValue('B13',$ObBrief);
$activeSheet->setCellValue('F12','Agreed Action:');
$activeSheet->setCellValue('F13',$ObAgreed);
$activeSheet->setCellValue('J12','Close Date:');
$activeSheet->setCellValue('J13',$ObDate);
$objPHPExcel->getActiveSheet()->getStyle('B11')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setRGB('D6D6D6');
//Good Practices
$objPHPExcel->getActiveSheet()->mergeCells('B20:M20');
$objPHPExcel->getActiveSheet()->mergeCells('B21:E21');
$objPHPExcel->getActiveSheet()->mergeCells('F21:I21');
$objPHPExcel->getActiveSheet()->mergeCells('J21:M21');
$objPHPExcel->getActiveSheet()->mergeCells('B22:E26');
$objPHPExcel->getActiveSheet()->mergeCells('F22:I26');
$objPHPExcel->getActiveSheet()->mergeCells('J22:M26');
$objPHPExcel->getActiveSheet()->mergeCells('B27:M28');
$activeSheet->setCellValue('B20','GOOD PRACTICES (Commendable acts and actions, Improvements, Innovations etc).');
$activeSheet->setCellValue('B21','Brief Description:');
$activeSheet->setCellValue('B22',$GoBrief);
$activeSheet->setCellValue('F21','Agreed Action:');
$activeSheet->setCellValue('F22',$GoAgreed);
$activeSheet->setCellValue('J21','Close Date:');
$activeSheet->setCellValue('J22',$GoDate);
$objPHPExcel->getActiveSheet()->getStyle('B20')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setRGB('D6D6D6');
//Feedback Given & Received
$objPHPExcel->getActiveSheet()->mergeCells('B29:M29');
$objPHPExcel->getActiveSheet()->mergeCells('B30:E30');
$objPHPExcel->getActiveSheet()->mergeCells('F30:I30');
$objPHPExcel->getActiveSheet()->mergeCells('J30:M30');
$objPHPExcel->getActiveSheet()->mergeCells('B31:E35');
$objPHPExcel->getActiveSheet()->mergeCells('F31:I35');
$objPHPExcel->getActiveSheet()->mergeCells('J31:M35');
$objPHPExcel->getActiveSheet()->mergeCells('B36:M37');
$activeSheet->setCellValue('B29','FEEDBACK GIVEN & RECEIVED');
$activeSheet->setCellValue('B30','Brief Description:');
$activeSheet->setCellValue('B31',$FeBrief);
$activeSheet->setCellValue('F30','Agreed Action:');
$activeSheet->setCellValue('F31',$FeAgreed);
$activeSheet->setCellValue('J30','Close Date:');
$activeSheet->setCellValue('J31',$FeDate);
$objPHPExcel->getActiveSheet()->getStyle('B29')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setRGB('D6D6D6');
//General Impression
$objPHPExcel->getActiveSheet()->mergeCells('B38:M38');
$objPHPExcel->getActiveSheet()->mergeCells('B39:G39');
$objPHPExcel->getActiveSheet()->mergeCells('H39:M39');
$objPHPExcel->getActiveSheet()->mergeCells('B40:G40');
$objPHPExcel->getActiveSheet()->mergeCells('H40:M40');
$objPHPExcel->getActiveSheet()->mergeCells('B41:M41');
$objPHPExcel->getActiveSheet()->mergeCells('B42:K42');
$objPHPExcel->getActiveSheet()->mergeCells('L42:M42');
$objPHPExcel->getActiveSheet()->mergeCells('B43:K43');
$objPHPExcel->getActiveSheet()->mergeCells('L43:M43');
$objPHPExcel->getActiveSheet()->mergeCells('B44:K44');
$objPHPExcel->getActiveSheet()->mergeCells('L44:M44');
$objPHPExcel->getActiveSheet()->mergeCells('B45:K45');
$objPHPExcel->getActiveSheet()->mergeCells('L45:M45');
$objPHPExcel->getActiveSheet()->mergeCells('B46:K46');
$objPHPExcel->getActiveSheet()->mergeCells('L46:M46');
$objPHPExcel->getActiveSheet()->mergeCells('B47:M47');
$objPHPExcel->getActiveSheet()->mergeCells('B48:K48');
$objPHPExcel->getActiveSheet()->mergeCells('L48:M48');
$objPHPExcel->getActiveSheet()->mergeCells('B49:K49');
$objPHPExcel->getActiveSheet()->mergeCells('L49:M49');
$objPHPExcel->getActiveSheet()->mergeCells('B50:K50');
$objPHPExcel->getActiveSheet()->mergeCells('L50:M50');
$objPHPExcel->getActiveSheet()->mergeCells('B51:K51');
$objPHPExcel->getActiveSheet()->mergeCells('L51:M51');
$objPHPExcel->getActiveSheet()->mergeCells('B52:K52');
$objPHPExcel->getActiveSheet()->mergeCells('L52:M52');
$objPHPExcel->getActiveSheet()->mergeCells('B53:M54');
$activeSheet->setCellValue('B38','GENERAL IMPRESSION');
$activeSheet->setCellValue('B39','1 = No evidence / poor / no understanding');
$activeSheet->setCellValue('H39','2 = Some evidence / understanding / not consistent');
$activeSheet->setCellValue('B40','3 = Requirements in place / basic unerstanding');
$activeSheet->setCellValue('H40','4 = Detailed understanding / more than minimum standards');
$objPHPExcel->getActiveSheet()->getStyle('B38')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setRGB('D6D6D6');
$activeSheet->setCellValue('B41','CULTURE');
$activeSheet->setCellValue('B42','Is the CDP obvious - You Said / We Did Boards; Feedback Stations; Posters?:');
$activeSheet->setCellValue('L42',$Q1);
$activeSheet->setCellValue('B43','Are there any Speak Up Coaches on this site?');
$activeSheet->setCellValue('L43',$Q2);
$activeSheet->setCellValue('B44','Are Focus Leader meetings happening?:');
$activeSheet->setCellValue('L44',$Q3);
$activeSheet->setCellValue('B45','Mention the Mental Tools, do people understand them?:');
$activeSheet->setCellValue('L45',$Q4);
$activeSheet->setCellValue('B46','Ask what "Never Harm" means to the teams:');
$activeSheet->setCellValue('L46',$Q5);
$objPHPExcel->getActiveSheet()->getStyle('B41')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setRGB('D6D6D6');
$activeSheet->setCellValue('B47','SYSTEM');
$activeSheet->setCellValue('B48','Are first impressions good, site signage, induction etc?:');
$activeSheet->setCellValue('L48',$Q6);
$activeSheet->setCellValue('B49','Is the site tidy, well laid out etc?:');
$activeSheet->setCellValue('L49',$Q7);
$activeSheet->setCellValue('B50','Are morning briefings / daily risk assessment carried out?:');
$activeSheet->setCellValue('L50',$Q8);
$activeSheet->setCellValue('B51','Have all the team been briefed & signed onto the RAMS?:');
$activeSheet->setCellValue('L51',$Q9);
$activeSheet->setCellValue('B52','Ask what they would do if there was a change in the work activity i.e. not in RAMS?:');
$activeSheet->setCellValue('L52',$Q10);
$objPHPExcel->getActiveSheet()->getStyle('B47')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setRGB('D6D6D6');
//Comments
$objPHPExcel->getActiveSheet()->mergeCells('B55:M55');
$objPHPExcel->getActiveSheet()->mergeCells('B56:M63');
$objPHPExcel->getActiveSheet()->mergeCells('B64:M65');
$activeSheet->setCellValue('B55','Additional Comments:');
$activeSheet->setCellValue('B56',$Add);
$objPHPExcel->getActiveSheet()->getStyle('B55')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setRGB('D6D6D6');
//Completed By
$objPHPExcel->getActiveSheet()->mergeCells('B66:M66');
$objPHPExcel->getActiveSheet()->mergeCells('B67:C67');
$objPHPExcel->getActiveSheet()->mergeCells('D67:G67');
$objPHPExcel->getActiveSheet()->mergeCells('H67:I67');
$objPHPExcel->getActiveSheet()->mergeCells('J67:M67');
$objPHPExcel->getActiveSheet()->mergeCells('B68:C68');
$objPHPExcel->getActiveSheet()->mergeCells('D68:G68');
$objPHPExcel->getActiveSheet()->mergeCells('H68:M68');
$objPHPExcel->getActiveSheet()->mergeCells('B69:M70');
$activeSheet->setCellValue('B66','COMPLETED BY');
$activeSheet->setCellValue('B67','Name:');
$activeSheet->setCellValue('D67',$Name);
$activeSheet->setCellValue('H67','Title:');
$activeSheet->setCellValue('J67',$Title);
$activeSheet->setCellValue('B68','Date:');
$activeSheet->setCellValue('D68',$Date);
$objPHPExcel->getActiveSheet()->getStyle('B66')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setRGB('D6D6D6');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('Senior Managers Site Tour.xls');
?>
Seems that are using wrong PHPExcel version and you need to re-install the library
See [this answer] for more details.
Investigation
After a code follow-through via PHPExcel repository on GitHub the following observations can be made:
When PHPExcel is instantiated, it's constructor builds worksheets array with one Worksheet.
// Initialise worksheet collection and add one worksheet
$this->workSheetCollection = array();
$this->workSheetCollection[] = new PHPExcel_Worksheet($this);
Notice that Worksheet, when instantiated, gets the PHPExcel instance into its constructor. And this object is assigned to the Worksheets property parent:
public function __construct(PHPExcel $pParent = null, $pTitle = 'Worksheet')
{
// Set parent and title
$this->parent = $pParent;
...
Now, we see that the setTitle method is called from the Worksheet:
$objPHPExcel->getActiveSheet()->setTitle('Senior Managers Site Tour');
Inside setTitle there's the following code:
if ($this->parent) {
// Is there already such sheet name?
if ($this->parent->sheetNameExists($pValue)) {
...
And here the exception is thrown.
We can clearly see the method present in PHPExcel code and we can see that the parent is correctly recognized as a member of this class. So the only conclusion is that wrong version of PHPExcel.php is used. The missing function has only been added in v. 1.8.
I am implementing a PHP SOAP server using a third party wsdl. The included xsd has an reference to the external schema as bellow:
<xsd:import schemaLocation="http://www.w3.org/TR/2008/REC-xmldsig-core-20080610/xmldsig-core-schema.xsd" namespace="http://www.w3.org/2000/09/xmldsig"/>
The SoapClient with bellow code works perfectly:
$options = array();
$options['features'] = 1;
$options['trace'] = 1;
$options['connection_timeout'] = 2000;
$options['exceptions'] = 1;
$options['soap_version'] = SOAP_1_1;
$options['encoding'] = 'UTF-8';
$options["user_agent"] = 'php-file_get_contents/'.phpversion();
$clent = new SoapClient( $wsdl, $options);
But not the SoapServer
$options = array();
$options['features'] = 1;
$options['trace'] = 1;
$options['connection_timeout'] = 2000;
$options['exceptions'] = 1;
$options['soap_version'] = SOAP_1_1;
$options['encoding'] = 'UTF-8';
$server = new SoapServer($wsdl, $options);
Which trows the following error
SoapServer::SoapServer("http://www.w3.org/TR/2008/REC-xmldsig-core-20080610/xmldsig-core-schema.xsd"): failed to open stream: HTTP request failed! HTTP/1.0 500 Server Error\r\n in ..../index.php on line 54
PHP Warning: SoapServer::SoapServer(): I/O warning : failed to load external entity "http://www.w3.org/TR/2008/REC-xmldsig-core-20080610/xmldsig-core-schema.xsd" in ..../index.php on line 54
PHP Fatal error: SOAP-ERROR: Parsing Schema: can't import schema from 'http://www.w3.org/TR/2008/REC-xmldsig-core-20080610/xmldsig-core-schema.xsd' in .../index.php on line 54
The SoapClient was also throwing the same error, but which is resolved after adding the "user_agent" option.
I don't see a "user_agent" option for SoapServer.
am I missing something here?
I am able to access the url: http://www.w3.org/TR/2008/REC-xmldsig-core-20080610/xmldsig-core-schema.xsd and able to download the xsd file
Edited: Added the actual xsd link.
I've recently had a problem where the SOAP calls to the ID3Global/address service suddenly stopped working(they previously worked fine). I believe it has something to do with the hosting provider turning off allow_url_fopen on our server which now means the service doesn't work.
I've been told I'll need to switch to using cURL to grab the files (WSDL) as file_get_contents requires 'allow_url_fopen' to be set in the php.ini file for this to work. However I don't seem to be using file_get_contents in my file to get the WSDL file.
How can I to switch to using cURL?
Here's my PHP file making the SOAP address call:
<?php
ini_set("soap.wsdl_cache_enabled", "0");
$username = 'xxxxxxx#xxxxxxxx.com';
$password = 'xxxxxxx';
$profile_id = 'xxxxxx-xxxx-xxxx-xxxx-xxxxxxxx';
// Live WSDL
$wsdl = 'https://id3global.com/ID3gWS/ID3global.svc?wsdl';
$postcode = $_POST['ZipPostcode'];
/**
* Method to arrange the address into a sane
* order for displaying back to the user
*
* #param $item
* #param $key
* #internal param $address
*/
function sortAddress(&$item, $key)
{
// Convert the object to an array
$address = (array) $item;
// Reorder the address lines
$addressLines = array(
'Company' => $address['Company'],
'Building' => $address['Building'],
'SubBuilding' => $address['SubBuilding'],
'Premise' => $address['Premise'],
'SubStreet' => $address['SubStreet'],
'Street' => $address['Street'],
'City' => $address['City'],
'StateDistrict' => $address['StateDistrict'],
'ZipPostcode' => $address['ZipPostcode'],
'Country' => $address['Country'],
);
// Remove blank address lines
// $item = array_filter($addressLines);
$item = $addressLines;
}
class clsWSSEAuth {
private $Username;
private $Password;
function __construct($username, $password) {
$this->Username=$username;
$this->Password=$password;
}
}
class clsWSSEToken {
private $UsernameToken;
function __construct ($UsernameToken){
$this->UsernameToken = $UsernameToken;
}
}
$strWSSENS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
//Auth
$objSoapVarUser = new SoapVar($username, XSD_STRING, NULL, $strWSSENS, NULL, $strWSSENS);
$objSoapVarPass = new SoapVar($password, XSD_STRING, NULL, $strWSSENS, NULL, $strWSSENS);
$objWSSEAuth = new clsWSSEAuth($objSoapVarUser, $objSoapVarPass);
//Token
$objSoapVarWSSEToken = new SoapVar($objWSSEAuth, SOAP_ENC_OBJECT, NULL, $strWSSENS, 'UsernameToken', $strWSSENS);
$objWSSEToken = new clsWSSEToken($objSoapVarWSSEToken);
//Header
$objSoapVarWSSEAuth = new SoapVar($objWSSEToken, SOAP_ENC_OBJECT, NULL, $strWSSENS, 'UsernameToken', $strWSSENS);
$objSoapVarHeaderVal = new SoapVar($objSoapVarWSSEAuth, SOAP_ENC_OBJECT, NULL, $strWSSENS, 'Security', $strWSSENS);
$objSoapVarWSSEHeader = new SoapHeader($strWSSENS, 'Security', $objSoapVarHeaderVal, true);
//Client
$client = new SoapClient($wsdl, array(
'soap_version' => SOAP_1_1,
'trace' => 1,
'exception' => true,
));
$client->__setSoapHeaders($objSoapVarWSSEHeader);
$results = $client->AddressLookup(array(
'InputData' => array('ZipPostcode' => strtoupper($postcode)),
));
$addresses = $results->AddressLookupResult->GlobalAddress;
array_walk($addresses, 'sortAddress');
//var_dump($addresses);
echo json_encode( $addresses );
This is triggered using AJAX and here's the JavaScript/jQuery file:
jQuery(document).ready(function($) {
var addresses = [];
$("body").on('click', '.find-address', function(e){
e.preventDefault();
url = '/wp-content/themes/Cornhill/gbgroup-address-lookup_2.php';
postode_id = $(this).data('postcode');
address_id = $(this).data('address');
postcode = $('#'+postode_id).val();
console.log('Stage 1');
if (postcode != '')
{
var addressList = $('#'+address_id);
addressList.find('option').remove();
opt = $('<option>').html('Loading...');
opt.val('');
addressList.append(opt);
console.log('stage 2');
$.ajax({
url: url,
dataType: 'json',
type: 'post',
data: {
'ZipPostcode': postcode
},
success: function(response){
addressList.find('option').remove();
addresses[address_id] = response;
opt = $('<option>').html('Please select');
opt.val('');
addressList.append(opt);
for(x=0; x<addresses[address_id].length; x++){
addressArray = new Array();
addressArray.push(addresses[address_id][x].Building);
addressArray.push(addresses[address_id][x].Street);
addressArray.push(addresses[address_id][x].City);
addressArray.push(addresses[address_id][x].ZipPostcode);
addressString = addressArray.join(', ');
opt = $('<option>').attr('value', x);
opt.html(addressString);
addressList.append(opt);
}
}
});
}
else
{
return;
}
});
$("body").on('change', '.select-address', function(){
address_id = $(this).attr('id');
street_id = $(this).data('street');
town_id = $(this).data('town');
postcode_id = $(this).data('postcode');
value = $(this).val();
if(value != ''){
address = addresses[address_id][value];
if (address.Building != '')
{
$('#'+street_id).val(address.Building+' '+address.Street);
}
else
{
$('#'+street_id).val(address.Street);
}
$('#'+town_id).val(address.City);
$('#'+postcode_id).val(address.ZipPostcode);
}
});
});
I've previously tried switching using the following code to grab the WSDL file but am not really sure what else I'm supposed to do with it:
$ch = curl_init('https://id3global.com/ID3gWS/ID3global.svc?wsdl');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$resultSuper = curl_exec($ch);
The parameter allow_url_fopen has no effect on the way that SOAP works. You can easily test this with the following script:
<?php
echo "allow_url_fopen status is: " . ini_get('allow_url_fopen') . "\n";
$wsdl = 'https://id3global.com/ID3gWS/ID3global.svc?wsdl';
file_get_contents($wsdl);
$client = new SoapClient($wsdl, array(
'soap_version' => SOAP_1_1,
'trace' => 1,
'cache_wsdl' => WSDL_CACHE_NONE, // this is important for the purpose of the test
'exception' => true,
));
print_r($client);
?>
When allow_url_fopen is enabled, you will see the following output:
allow_url_fopen status is: 1 SoapClient Object ( [trace] => 1 [_soap_version] => 1 [sdl] => Resource id #11 )
When allow_url_fopen is disabled, you will see the following output:
allow_url_fopen status is: 0
Warning: file_get_contents(): https:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /var/www/test.php on line 9
Warning: file_get_contents(https://id3global.com/ID3gWS/ID3global.svc?wsdl): failed to open stream: no suitable wrapper could be found in /var/www/test.php on line 9
SoapClient Object ( [trace] => 1 [_soap_version] => 1 [sdl] => Resource id #10 )
Notice that no SOAP error is reported.
The reason for this behaviour is the following code in file ext/soap/php_xml.c in PHP's source:
old_allow_url_fopen = PG(allow_url_fopen);
PG(allow_url_fopen) = 1;
ctxt = xmlCreateFileParserCtxt(filename);
PG(allow_url_fopen) = old_allow_url_fopen;
So, allow_url_fopen is enabled for the WSDL download. If you comment the lines as follows:
/* old_allow_url_fopen = PG(allow_url_fopen);
PG(allow_url_fopen) = 1; */
ctxt = xmlCreateFileParserCtxt(filename);
/* PG(allow_url_fopen) = old_allow_url_fopen; */
And compile PHP with the changed source, you will see the following results:
Enabled allow_url_fopen:
allow_url_fopen status is: 1 SoapClient Object ( [trace] => 1 [_soap_version] => 1 [sdl] => Resource id #11 )
Disabled allow_url_fopen:
allow_url_fopen status is: 0
Warning: file_get_contents(): https:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /var/www/test.php on line 9
Warning: file_get_contents(https://id3global.com/ID3gWS/ID3global.svc?wsdl): failed to open stream: no suitable wrapper could be found in /var/www/test.php on line 9
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://id3global.com/ID3gWS/ID3global.svc?wsdl' : failed to load external entity "https://id3global.com/ID3gWS/ID3global.svc?wsdl" in /var/www/test.php:16 Stack trace: #0 /var/www/test.php(16): SoapClient->SoapClient('https://id3glob...', Array) #1 {main} thrown in /var/www/test.php on line 16
You can see that this time we have fatal SOAP error and that the WSDL cannot be loaded. I observed this behaviour with PHP 5.4.40 and PHP 5.6.8.
I am using SOAP to get data from some server (data coming in .xml) . But sometimes SOAP server is down and I need to display some error message instead of :
Warning: simplexml_load_string(): Entity: line 2: parser error : Start tag expected, '<' not found in /var/www/class/data2.php on line 619 Warning: simplexml_load_string(): in /var/www/class/data2.php on line 619 Warning: simplexml_load_string(): ^ in /var/www/class/data2.php
My code is:
$client = new SOAPClient ( 'link.wsdl' ); // initiate new SoapClient
$password ['_'] = 'PASSWORD'; // password for authenticate_user function in SoapHeader
$encoded = new SoapVar ( $password, SOAP_ENC_OBJECT ); // make SoapVariable out of $password
$header = new SoapHeader ( 'http://soapinterop.org/echoheader/', 'authenticate_user', $encoded ); // put authenticate_user method, and password in header
$client->__setSoapHeaders ( $header ); // set SoapHeader
$response = $client->get_details ($this->vin); // calling get_details with the vin given in the form field
$xml = simplexml_load_string ( $response ); // converting the response string to xml
$json = json_encode ( $xml ); // converting to an array in to easy steps (step 1)
$array = json_decode ( $json, TRUE ); // step 2
What I want:
Replace Warning message with something like: "This service is temporary unavaliable"
After
$xml = simplexml_load_string ( $response );
check if
$xml === false
and set the error message accordingly
http://php.net/manual/en/function.simplexml-load-string.php
As you can read in manual the simplexml_load_string function:
Returns an object of class SimpleXMLElement with properties containing the data held within the xml document, or FALSE on failure.
So simply check if it fails and if it does echo your This service is temporary unavaliable
To get rid of this warning consider to ini_set('display_errors', '0'); on production