19

In PHP: I am getting an error:

SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://xxx.xxxx.asmx?WSDL' : failed to load external entity "http://xxx.xxxx.asmx?WSDL"

My code is:

<?php
header('Content-Type: text/plain');
if (!class_exists('SoapClient')) {
    die ("You haven't installed the PHP-Soap module.");
}

ini_set('max_execution_time', 1);
try {
    $options = array(
        'soap_version' => SOAP_1_2,
        'exceptions'   => true,
        'trace'        => 1,
        'cache_wsdl'   => WSDL_CACHE_NONE
    );
    $client = new SoapClient('http://xxx.xxxx.asmx?WSDL', $options);
    // Note where 'CreateIncident' and 'request' tags are in the XML
    $results = $client->CreateIncident(
        array(
            'FirstName'         => 'gyaan',
            'LastName'          => 'p',
            'Email'             => 'aa@gmail.com',
            'QueryProductClass' => 'QueryProductClass',
            'ChannelCode'       => 12,
            'CampaignCode'      => 234,
            'Lob'               => 'Lob',
            'PackageName'       => 'SEONI',
            'PackageCode'       => 'SMP',
            'TravelYear'        => 2012,
            'TravelMonth'       => 06,
            'TravelDay'         => 29,
            'CityOfResidence'   => 'Jabalpur',
            'ncidentNotes'      => 'testing ignor this',
            'MobilePhone'       => '1234567890',
            'DepartureCity'     => 'bangalore',
            'NoOfDaysTravel'    => '3 Days',
            'VendorName'        => 'TEST HIQ'
        )
    );
}
catch (Exception $e) {
    echo "<h2>Exception Error!</h2>";
    echo $e->getMessage();
}
?>

Please tell me where i am making mistake i am new in WSDL and soap

Habib
  • 591
  • 8
  • 29
Gyaneshwar Pardhi
  • 471
  • 1
  • 4
  • 15

13 Answers13

29

I solved this on my WAMP setup by enabling the php_openssl extension, since the URL I was loading from used https://.

adamdport
  • 11,687
  • 14
  • 69
  • 91
6

I had exactly the same error message. In my case, making an entry in my /etc/hosts file (on the server hosting the service) for the target server referenced in the WSDL fixed it.

Kind of a strangely worded error message..

biegleux
  • 13,179
  • 11
  • 45
  • 52
Lee Henkel
  • 111
  • 2
  • 4
6

I had this problem and it took me hours to figure out. The mainly reason of this error is the SoapClient cannot stream the web service file from the host. I uncommented this line "extension=php_openssl.dll" in my php.ini file and it works.

minhnguyen
  • 91
  • 1
  • 3
6

Try this:

$Wsdl = 'http://xxxx.xxx.xx/webservice3.asmx?WSDL';
libxml_disable_entity_loader(false); //adding this worked for me
$Client = new SoapClient($Wsdl);
//Code...
Rohit Dhiman
  • 2,691
  • 18
  • 33
4

If you want to use that on localhost, then use WAMP.

Then click on tray icon>PHP Services> and there enable the followings:

  • SOAP
  • php_openssl
  • openssl
  • curl

p.s. some free web-hosting may not have those options

Tordek
  • 10,628
  • 3
  • 36
  • 67
T.Todua
  • 53,146
  • 19
  • 236
  • 237
3

Try adding this piece of code. It worked for me.

$opts = array(
    'ssl' => array(
        'ciphers'     => 'RC4-SHA',
        'verify_peer' => false, 
        'verify_peer_name' => false 
    ),
);

// SOAP 1.2 client
$params = array(
    'encoding'           => 'UTF-8',
    'verifypeer'         => false,
    'verifyhost'         => false,
    'soap_version'       => SOAP_1_2,
    'trace'              => 1,
    'exceptions'         => 1,
    'connection_timeout' => 180,
    'stream_context'     => stream_context_create( $opts ),
);
$url = 'http://www.webservicex.net/globalweather.asmx?WSDL';

try {
    $client = new SoapClient( $url, $params );
} catch ( SoapFault $fault ) {
    echo '<br>' . $fault;
}
Gleb Kemarsky
  • 10,160
  • 7
  • 43
  • 68
Jahson kyalo
  • 301
  • 2
  • 11
2

I got the same error and I solved it looking for the soap settings in the php.ini file and changing soap.wsdl_cache_enabled=1 to soap.wsdl_cache_enabled=0

Jose Daniel
  • 391
  • 4
  • 17
1

add the dns entry to your system hosts file
for example:http://aaa.com/service.asmx?WSDL
you can get the aaa.com's ip address with ping
and then add to the hosts file

curzduff
  • 91
  • 1
  • 2
1

Enable all these from php.ini configuration file

extension=php_openssl.dll
extension=php_curl.dll
extension=php_xmlrpc.dll
Gowri
  • 1,832
  • 3
  • 29
  • 53
vijaymmali
  • 21
  • 2
1

you can use this option for call soap with wdsl :

$opts = array(
            'http' => array(
                'user_agent' => 'PHPSoapClient'
            )
        );
        $context = stream_context_create($opts);

        $soapClientOptions = array(
            'stream_context' => $context,
            'cache_wsdl' => WSDL_CACHE_NONE
        );

        $wsdlUrl = 'your wsdl url';
        $soapClient = new SoapClient($wsdlUrl, $soapClientOptions);

        $result = $soapClient->VerifyTransaction($refNum, $MerchantCode);
Amir Kaftari
  • 1,305
  • 14
  • 13
0

Similar error as well. Realized I had an .htpasswd setup for the particular host. Uncommented it from the .htaccess file and worked fine.

rafiki_rafi
  • 1,177
  • 2
  • 11
  • 27
0

I got the same error

Could not connect to the Magento WebService API: SOAP-ERROR: Parsing WSDL: Couldn't load from 'example.com/api/soap/?wsdl' : failed to load external entity "example.com/api/soap/?wsdl"

and my issue resolved once I update my Magento Root URL to

example.com/index.php/api/soap/?wsdl

Yes, I was missing index.php that causes the error.

saiid
  • 635
  • 1
  • 6
  • 20
0

As mentioned in earlier responses, this error can occur when interacting with a SOAP service over an HTTPS connection, and an issue is identified with the connection. The issue may be on the remote end (invalid cert) or on the client (in case of missing CA or PEM files). See http://php.net/manual/en/context.ssl.php for all possible SSL context settings. In my case, setting the path to my local certificate resolved the issue:

$context = ['ssl' => [
    'local_cert' => '/path/to/pem/file',
]];

$params = [
    'soap_version' => SOAP_1_2, 
    'trace' => 1, 
    'exceptions' => 1, 
    'connection_timeout' => 180, 
    'stream_context' => stream_context_create($context), 
    'cache_wsdl' => WSDL_CACHE_NONE, // eliminate possible issue from cached wsdl
];

$client = new SoapClient('https://remoteservice/wsdl', $params);
user4603841
  • 1,246
  • 9
  • 8