Home >Backend Development >PHP Tutorial >Why Does My SoapClient Fail to Parse WSDL on Linux But Work on WAMP?

Why Does My SoapClient Fail to Parse WSDL on Linux But Work on WAMP?

Linda Hamilton
Linda HamiltonOriginal
2024-11-08 06:34:02844browse

Why Does My SoapClient Fail to Parse WSDL on Linux But Work on WAMP?

SOAP Error: Parsing WSDL: Unable to Load from WSDL URL

Question

On a Linux master server, the SoapClient is unable to parse the WSDL from a given URL, resulting in the error: "SOAP-ERROR: Parsing WSDL: Couldn't load from - but works on WAMP". However, calling the URL directly or using curl from the command line returns the expected XML response.

Answer

Missing User Agent String:

For certain versions of PHP, the SoapClient may not send HTTP user agent information by default. This can cause issues with the web service being used.

Solution:

Explicitly set the user agent using a context stream:

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

$wsdlUrl = 'http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl';
$soapClientOptions = array(
    'stream_context' => $context,
    'cache_wsdl' => WSDL_CACHE_NONE
);

$client = new SoapClient($wsdlUrl, $soapClientOptions);

Web Service Issues:

Additionally, it was discovered that the web service in question had issues with IPv6 requests without a user agent string. To verify this, try the following commands on the Linux host:

curl  -A ''  -6 http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl
curl  -A 'cURL User Agent'  -6 http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl

curl  -A ''  -4 http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl
curl  -A 'cURL User Agent'  -4 http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl

The IPv6 request without a user agent will fail, while all other requests will succeed. This suggests that the Linux host is resolving the web service's domain to its IPv6 address, and the SoapClient was not adding a user agent string by default.

The above is the detailed content of Why Does My SoapClient Fail to Parse WSDL on Linux But Work on WAMP?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn