I tried to make a soap request but i always faced the same error until i disabled the remote_stream_wrapper module.

Here is my soap call :
$soap = new SoapClient('http://example.com?wsdl');
Here is the error :
SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://example.com?wsdl' : failed to load external entity "http://example.com?wsdl"

I figured out that this is produced when it reach the DrupalRemoteStreamWrapper::stream_stat, precisely :
$request = drupal_http_request($this->uri, array('method' => 'HEAD')); in file remote_stream_wrapper.inc line 273

This is because my wsdl service is only reachable through GET method, the HEAD method return a "500 Erreur Interne de Servlet"

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Jovean’s picture

Priority: Normal » Major

You can work around this by storing a copy of the SOAP services WSDL locally using CURL with something like this:

$local_wsdl_path = variable_get('file_public_path', conf_path() . '/files') . '/local_wsdl.xml';
$local_wsdl = fopen($local_wsdl_path, 'w');

$curl_handler = curl_init('http://example.com/WSDL.xml');
curl_setopt($curl_handler, CURLOPT_FILE, $local_wsdl);
curl_setopt($curl_handler, CURLOPT_HEADER, 0);
curl_exec($curl_handler);
curl_close($curl_handler);

fclose($local_wsdl);
Jovean’s picture

Priority: Major » Normal

undoing priority change that I didn't intend.

raytiley’s picture

Status: Active » Needs review
FileSize
814 bytes

This patch falls back to GET if HEAD returns an error.

openminds’s picture

FYI: This patch fixes a problem we experienced using a Soapclient call within a Drupal+Commerce Kickstart setup

Fernly’s picture

#3 seems to work for me. Error fixed.

twistor’s picture

Title: Unable to make Soap request with remote_stream_wrapper enabled. » Fallback to GET if HEAD not allowed.
Issue summary: View changes
Issue tags: -soap, -Soap Client, -soapclient
FileSize
3.36 KB

This patch fixes a few things:

1) It removes the HEAD request from stream_stat(). stream_stat() is called in response to fstat() meaning we have already downloaded the file, so just return the length of the content. That alone should fix the previous issue.
2) Allows HTTP responses with zero length. That's a perfectly valid HTTP response, there's no reason to consider it invalid.
3) in url_stat() try a HEAD request, then fallback to a GET request. url_stat() is called in response to stat() meaning we don't already have an open file handle.

paul.linney’s picture

Status: Needs review » Reviewed & tested by the community

Patch in #6 fixed the issue for my current project, that uses a number of SOAP services :)

Paul

NotGoddess’s picture

I was running into issues with SOAP too - SOAP-ERROR: Parsing WSDL: Couldn't load from external entity.
My calls would work with pure PHP and on other Drupal sites but not one particular install. I didn't make the connection with remote stream wrapper being enabled until after hours of debugging.

The patch in #6 solved my issue and it doesn't seem to conflict with why I have RSW on the site - external resources. They still work just fine.

Chris Gillis’s picture

I've been having the same SOAP error. Took me ages to track it to this module... turn the module off, SoapClient works fine. Switch it on and SOAP-ERROR: Parsing WSDL: Couldn't load from [redacted] : failed to load external entity. I've tried the patch in #6 against 7.x-1.0-rc1 and it does NOT fix my error... Any other ideas?

arek611’s picture

Using patch in #3 with rc1 and it fixed the issue on our end with Drupal Commerce and the Click&Pledge payment gateway.

rkostov’s picture

The patch in #6 (version 7.x-1.0-rc1) doesn't fix my error because it looks for '$request->code == 405' in doUrlStat(). But the error I have is -1002. The patch in #3 does fix the error.