There are some questions in SO with the same problem, but any of them helped me.
Here is my code to call a Soap Web service:
$client = new SoapClient($wsdl, array(
'soap_version' => SOAP_1_1,
'trace' => 1,
'exceptions'=> true,
'encoding' => 'UTF-8',
'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_DEFLATE,
'cache_wsdl' => WSDL_CACHE_NONE
))
$params = new SoapVar($xmlString, XSD_ANYXML, null, null);
try {
$client->functionName($params);
catch (SoapFault $f) {
print_r ($f);
}
This is (part of) the SoapFault Object:
SoapFault Object
(
[message:protected] => Could not connect to host
[string:Exception:private] =>
[code:protected] => 0
[file:protected] => /home/user/Documentos/Web/Client.class.php //fileName
[line:protected] => 49 //line where I have $client->functionName
[trace:Exception:private] => Array
(
[0] => Array
(
[function] => __doRequest
[class] => SoapClient
[type] => ->
[args] => Array
(
[0] => <?xml version="1.0" encoding="UTF-8"?> // the XML
[1] => https://example.company.com/WSDLName.svc //name of WSDL
[2] => http://example.org/Pull/functionName //URL with name of the function
[3] => 1
[4] => 0
)
)
[1] => Array
(
[file] => /home/user/Documentos/Web/Client.class.php //fileName
[line] => 49
[function] => __call
[class] => SoapClient
[type] => ->
[args] => Array
(
[0] => functionName
[1] => Array
(
[0] => SoapVar Object
(
[enc_type] => 147
[enc_value] => //the XML
)
)
)
)
If I call print_r($client->__getLastRequest());
and test the printed XML in SoapUI all works like a charm.
If I call print_r(file_get_contents($wsdl));
I got the WSDL file.
Trying var_dump($client->__getLastRequestHeaders())
, getting null
;
My attempts until now:
1) Putting a ini_set('soap.wsdl_cache_enabled',0);
just before the line $client = new SoapClient...
. Same error.
2) Changes the call line to $client->__soapCall('functionName',(array)$params)
. Same error. The only difference is the XML formatted with <
and
.
3) Change my soap options just to array('soap_version' => SOAP_1_1,'trace' => 1)
. Same error.
4) The wsdl URL is a http URL, so I believe that is not a SSL problem. However, in the SoapFault object, I receive the same URL with https, so I changed my $wsdl to the URL with https:// and receive the error SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://example.company.com/WSDLName.svc?wsdl'
.
As I said, all works fine in SoapUI.
Finally, here is my server info:
Ubuntu 14.04.3 LTS
Apache 2.4.7
PHP 5.5.9
Someone has any idea on what I doing wrong?
UPDATE
Following the comments below, here are more information:
1) Both http
and https
URLs in the browser returns the WSDL document.
2) If I ping the wsdl URL in terminal, I receive ping: unknown host https://example.org/Pull/functionName
. The WSDL also has a method named Ping, defined as:
<wsdl:operation name="Ping">
<soap:operation soapAction="http://tempuri.org/IPull/Ping" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
When I use it in PHP I got the same scenario: A Soap Fault "Could not connect to host", but the XML created works fine in SoapUI.
3) The result of var_dump($client)
is:
object(SoapClient)[42]
public 'trace' => int 1
public 'compression' => int 32
public '_encoding' => string 'UTF-8' (length=5)
public '_soap_version' => int 1
public 'sdl' => resource(30, Unknown)
Note: I got a workaround to deal with the problem that is definitively not the best option, but works. I created the whole XML body (inclusing the soap envelope) using DOMDocument
or SimpleXML
and send it via cURL
to the URL https://example.company.com/WSDLName.svc
.
It's ugly, but works to me for the moment while I'm waiting for any other solution.