HowTo connect WebServices via SOAP/PHP5.6.x

  • 0
  • 1
  • Question
  • Updated 3 years ago
  • Answered
  • (Edited)
Hi community,
I tried to connect the WebServices via SOAP/PHP in version 5.6.18.
The short script should request all END-System MAC addresses from the NAC Appliance.
Via Https://......  it works fine with the right output.
But my php script didn't work well because the wsdl file isn't accessible.
I use the Extreme pdf document "OFC-Web-Services.pdf" to try some examples.

ini_set("soap.wsdl_cache_enabled", "0");   //disable wsdl cache
$wsdl = "https://xxx.xxx.xxx.xxx:8443/axis/services/NACWebService?wsdl";
$client = new SoapClient($wsdl, array(
            'trace' => 1,
            'login' => "root",
            'password' => "password",
            'cache_wsdl' => WSDL_CACHE_NONE,
            'soap_version' => SOAP_1_2
));
$response = $client->getAllEndSystemMacs();
print_r($response);
?>


The cli output looks like:
PHP Fatal error:  SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://192.168.10.xx:8443/axis/services/NACWebService?wsdl' : failed to load external entity "https://xxx.xxx.xxx.xxx:8443/axis/services/NACWebService?wsdl";
in C:\xampp\htdocs\soap\phptest.php on line 10
PHP Fatal error:  Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://xxx.xxx.xxx.xxx:8443/axis/services/NACWebService?wsdl
' : failed to load external entity "https://xxx.xxx.xxx.xxx:8443/axis/services/NACWebService?wsdl";
in C:\xampp\htdocs\soap\phptest.php:10
Stack trace:
#0 C:\xampp\htdocs\soap\phptest.php(10): SoapClient->SoapClient('https://xxx.xxx...', Array)
#1 {main}
  thrown in C:\xampp\htdocs\soap\phptest.php on line 10
I'm
not so familiar with the php versions but i guess that there was some
changes from the php version in the document and the actual version
5.6.18.
I would be grateful for help

regards

Mike
Photo of Michael Althoff

Michael Althoff

  • 90 Points 75 badge 2x thumb

Posted 3 years ago

  • 0
  • 1
Photo of Matthew Hum

Matthew Hum, Principal Engineer, APAC

  • 1,542 Points 1k badge 2x thumb
Just a thought. Are you using a self signed cert on Netsight? Otherwise I think you need to have certificate validation disabled as described in:

http://stackoverflow.com/questions/84...


can you do a manual curl to the target?

curl -u root:password "https://<Netsight%20IP>:8443/ax..."

if it gives a certificate error try:

curl -k -u root:password "https://<Netsight%20IP>:8443/ax..."
(Edited)
Photo of Michael Althoff

Michael Althoff

  • 90 Points 75 badge 2x thumb
Hi Matthew,

thx for reply.
I tried the curl connections. Without the insecure-option "-k" I got a certifikate error

curl: (60) SSL certificate problem: unable to get local issuer certificate

WIth the -k option I can read the wsdl-file succesfully.

I had suspected that this is an issue with the access, but I cannot figure out where it come from, and how I can fix it.
The example, described in the thread above isn't working for me.


regards
Photo of Matthew Hum

Matthew Hum, Principal Engineer, APAC

  • 1,542 Points 1k badge 2x thumb
Ok, Those curl commands were to validate that it is a certificate error that you are encountering. your PHP is trying to validate the Netsight cert used in the HTTPS operation and is failing so it's not even trying to retrieve the call.

You need to enable self signed certificates with PHP in order for the soapclient to ignore the self signed certificate and continue retrieving the wsdl.

try using:
$contextOptions = array(
'ssl' => array(
'allow_self_signed' => true,
)
);
as shown here: http://stackoverflow.com/questions/12...
Photo of Michael Althoff

Michael Althoff

  • 90 Points 75 badge 2x thumb
Hi again,
I'm sorry but it doesn't work.
I'm still run into the error "Parsing WSDL: Couldn't load from 'http .........failed to load external entity".

$wsdl = "https://xxx.xxx.xxx.xxx:8443/axis/services/NACWebService?wsdl";
$contextOptions = array(
    'ssl' => array(
    'allow_self_signed' => true,
    ));
$sslContext = stream_context_create($contextOptions);
$soap = new SoapClient($wsdl, array(
            'stream_context' => $sslContext,
            'login' => "root",
            'password' => "password"));
$response = $soap->getNACVersion();
print_r($response);

When I use a local version from the "wsdl" file, I get the error only when the function is called
$response = $soap->getNACVersion(); 

I suspect that the credentials are submitted incorrectly or at the wrong place.
Could it really be so difficult to get running this simple code ?
I'm really frustrated.
Regards
Mike
(Edited)
Photo of Matthew Hum

Matthew Hum, Principal Engineer, APAC

  • 1,542 Points 1k badge 2x thumb
I'm sorry, I usually don't use PHP and do my calls via PERL. I talked to a friend and he said in PHP he uses the curl calls as external calls and parses the XML by himself. There are multiple ways to skin a cat, but if you are insistent on using the soapclient, I would try to look up the documentation of soapclient and see what is required for that.

The best way to troubleshoot this is to do a tcpdump and check the server response, whether or not the actual GET was sent or what HTTP status code was returned. 
Photo of Matthew Hum

Matthew Hum, Principal Engineer, APAC

  • 1,542 Points 1k badge 2x thumb
According to this: http://php.net/context.ssl
you need to include a few other options. try this:
$context = stream_context_create(array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
));
(Edited)