2

I've spent the last couple of days trying to figure out why my soap client can't connect, any help is appreciated. Very straightforward issue, my soap client;

$soapClient = new SoapClient("AXLAPI.wsdl", array('trace'=>true, 'exceptions'=>true,'location'=>"https://ip_address:8443/axl",
'login' => "username",'password'=> "password"));

Yields this very common error;

Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in /var/www/html/axl_test.php:18 Stack trace: #0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'https://ip_address...', 'CUCM:DB ver=8.5...', 1, 0) #1 /var/www/html/axl_test.php(18): SoapClient->__call('getLine', Array) #2 /var/www/html/axl_test.php(18): SoapClient->getLine(Array) #3 {main} thrown in /var/www/html/axl_test.php on line 18

I run this exact same code on another server and it runs fine. I'm positive this is related to an SSL issue because a wireshark capture several retransmissions. Also, when I purposefully change the username and password to something false, the error stays the same. So, it must be occuring during the handshake. I can access the remote server from the soap client server with no problems and am able to log in.

The error seems to show that it's trying to connect via HTTP, but my URL specifically calls for HTTPS to be used. I really don't understand where the issue can be.

Kimomaru
  • 993
  • 4
  • 14
  • 30
  • 1
    That's not a SOAP error; *"Could not connect to hosts"* means that the TCP connection could not be established. Use sth. like `curl https://ip_address:8443/...` to check if you can establish a connection to that port at all. Since it's a non-standard port, chances are it's blocked by some kind of firewall in your network. – helmbert May 13 '15 at 19:25
  • 1
    Are you behind a proxy server or firewall? – J E Carter II May 13 '15 at 19:30
  • I am not behind any firewall at all. – Kimomaru May 13 '15 at 19:31
  • helmbert - when I try to connect with curl, it says that the cert is self-signed and that I can use -k to connect insecurely. When I do so, I get a blank output. But I can connect to, say, curl http://www.google.com and am able to get the page. – Kimomaru May 13 '15 at 19:39
  • helmbert - also, I should add that when I run the curl -k command from the server that is working, I also get blank output. – Kimomaru May 13 '15 at 19:41
  • @Kimomaru, your self-signed certificate is the issue here. By default, PHP's SOAP client will not connect to a site with an insecure certificate. I'm pretty sure that someone on this site asked about this before; I'll have a look. – helmbert May 14 '15 at 09:20
  • possible duplicate of [Disable certificate verification in PHP SoapClient](http://stackoverflow.com/questions/8443618/disable-certificate-verification-in-php-soapclient) – helmbert May 14 '15 at 09:21
  • helmbert - I suspected that the self-signed cert may have been the issue, but unfortunately it is not the case. When I run the php script at the command line, even after adding the suggested syntax, I get "Fatal error: Class 'SoapClient' not found in /var/www/html/axl_test.php on line 18". It seems to be failing before the attempted connections. Most posts I have read on the issue have suggested that I download the PHP source and compile it with soap enabled instead of using the precompiled binaries. Like I said, I just don't know enough about soap to know if this view is correct. – Kimomaru May 14 '15 at 11:19

1 Answers1

1

After days of working through this issue, I solved the problem. Some of the answers here were correct, there was a problem with the self-signed certificate (so the Soap client has to be made to not care), but another issue was the url itself. For whatever reason, putting in an IP address did not work, using the FQDN did. So, the complete code looks like this;

<?php
error_reporting(E_ALL);
ini_set('display_errors', True);
?>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="style1.css">
<title>AXL Test</title>

<?php

$context = stream_context_create(array('ssl' => array('verify_peer' => false, 'allow_self_signed' => true)));

$soapClient = new SoapClient("AXLAPI.wsdl", array('stream_context' => $context, 'trace'=>true, 'exceptions'=>true,'location'=>"https://hostname.domain.name:8443/axl",'login' => "username",'password'=> "password")); 
$response = $soapClient->getLine(array("routePartitionName"=>"partitionName", "pattern"=>"pattern"));
echo "<TR><TD class='body'>" .  $response->return->line->description . "</TD><TD class='body'>";

?>

This issue was particularly vexing because I was using tried-and-true code from another server where self-signed ceritificats and FQDNs didn't matter. Now it did, and I don't know why. In any case, I got it working. Thank you to everyone who provided feedback, I hope this helps others.

Kimomaru
  • 993
  • 4
  • 14
  • 30