PHP SoapClient fails with - Failed to load external entity
After spending hours researching and trying to figure out the problem I found a 2 years old post that somehow served my purpose.
Unfortunately I can't mark this as duplicate so I'll just link it here: SOAP error parsing wsl couldn't load from but works on wamp
I couldn't find this question because Google didn't tag it as using the Europa services.
Either way, my problem was that I needed to specify my user agent explicitly because Europa web services are too outdated and can't resolve IPv6 requests, only IPv4. Like so:
$opts = array(
'http'=>array(
'user_agent' => 'PHPSoapClient'
)
);
$context = stream_context_create($opts);
$client = new SoapClient('http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl',
array('stream_context' => $context,
'cache_wsdl' => WSDL_CACHE_NONE));
$result = $client->checkVat(array(
'countryCode' => 'DK',
'vatNumber' => '47458714'
));
The example uses the CheckVAT SOAP function but it works just as well for the CheckTIN function.
SoapClient LibXMLError: failed to load external entity, SOAP-ERROR: Parsing WSDL: Couldn't load
After 6 hours of headache, the ONLY solution is to download the WSDL files.
https://wsbeta.fedex.com/web-services
and
https://ws.fedex.com/web-services
It will always throw an error 500, because this is not the wsdl.
Once you download the wsdls from Technical Resources -> FedEx WebServices For Shipping -> GetStarted (click on "Rate Services" and then "Download WSDL or XML"), in your script you will need to load your locally stored WSDL and everything will work like a charm.
$this->_soapClient = new SoapClient("RateService_v13.wsdl", array('exceptions'=>true, 'trace' => true));
Have fun!
Related Topics
Destroy or Unset Session When User Close the Browser Without Clicking on Logout
Mysql_Real_Escape_String VS Addslashes
How to Sort an Array of Utf-8 Strings
Instantiate a Class with or Without Parentheses
Can You Add an If Statement in Order By
How to Use Curl Instead of File_Get_Contents
Convert PDF to Jpeg with PHP and Imagemagick
How to Add Text to an Image with PHP Gd Library
Send PHP Date to JavaScript Date Format
How to Convert JSON to Xml in PHP
Int((0.1+0.7)*10) = 7 in Several Languages. How to Prevent This
Replace Multiple Newlines, Tabs, and Spaces
Special Characters in PHP/Mysql