Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to connect to WSDL

I was working with older version of OpenSSL(OpenSSL 0.9.8o) and I was forced to use newer OpenSSL 1.0.1e-fips as the result I was unable to connect to WSDL:

Message: SoapClient::SoapClient(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

I need to disable SSL certification check, I tried:

    $client = new SoapClient("https://IP:443/sdk/vimService?wsdl",
        array(
            "trace" => 1,
            "location" => "https://IP:443/sdk/",
            "stream_context" => stream_context_create(
                array(
                    'ssl' => array(
                        'verify_peer'       => false,
                        'allow_self_signed' => true,
                    )
                )
            )
        ) 
    );

`

And it throw:

Message: SoapClient::SoapClient(): Peer certificate CN=localhost.localdom' did not match expected CN=SAME IP AS IN SoapClient()'

Then I added 'peer_name'=> 'localhost.localdom', in stream_context and then it says XML file is empty:

Fatal error: Uncaught SoapFault exception: [Client] looks like we got no XML document

PHP 5.5

like image 468
minus1 Avatar asked Aug 05 '14 15:08

minus1


People also ask

How do I access WSDL?

Select Open WebLogic Server Console from the menu. Get the IP address of the WebLogic server console from the browser URL field. Copy the WSDL URL from the Test WebServices page WSDL field to your browser or SOAP client's URL field.

How do I find my WSDL URL?

You can retrieve the outer-most WSDL file (defined by the <wsdl-file> element within the webservices. xml file) by appending the string /wsdl or /wsdl/ to the endpoint address, for example, http://example.com/services/stockquote/wsdl .


4 Answers

Okey, I was able to found issue.

You can avoid this mess using stable PHP 5.5 version

Recently I learned that error: "looks like we got no XML document" is caused because of PHP version - PHP 5.6 in 5.5 working like a charm.

How to fix it in PHP 5.6

1) Remove SSL certificate check in PHP 5.6:

In 5.6 version SSL certification was enabled by default, so if you want to disabled it you must pass context stream:

    "stream_context" => stream_context_create(
        array(
            'ssl' => array(
                'verify_peer'       => false,
                'verify_peer_name'  => false,
            )
        )
    )

2) Deleted ?wsdl and added .wsdl instead (with ?wsdl, it didn't worke for me)

<?php

$client = new SoapClient("https://IP:443/sdk/vimService.wsdl",
    array(
        "trace" => 1,
        "location" => "https://IP:443/sdk/",
        'exceptions' => 1,
        "stream_context" => stream_context_create(
            array(
                'ssl' => array(
                    'verify_peer'       => false,
                    'verify_peer_name'  => false,
                )
            )
        )
    ) 
);


$soapmsg["_this"] = array( "_" => "ServiceInstance", "type" => "ServiceInstance");

$result = $client->RetrieveServiceContent($soapmsg);
$ServiceContent = $result->returnval;

$soapmsg = NULL;
$soapmsg["_this"] = $ServiceContent->sessionManager;
$soapmsg["userName"] = "USERNAME";
$soapmsg["password"] = "PASSWORD";

$result = $client->Login($soapmsg);
$UserSession = $result->returnval;

echo "User, " . $UserSession->userName . ", successfully logged in!\n";

$soapmsg = NULL;
$soapmsg["_this"] = $ServiceContent->sessionManager;
$result = $client->Logout($soapmsg);
like image 97
minus1 Avatar answered Oct 04 '22 02:10

minus1


In my case stream_context_create didn't worked.
So I download this file here : https://curl.haxx.se/ca/cacert.pem

and placed it in my localhost as : F:\xampp\apache\cert.pem and gave the same path for openssl.cafile=F:\xampp\apache\cert.pem in my phpini

This made the localhost to acquire certificate and things worked great...!! Posting this in case this may help some one going through my situation.

like image 24
Jasdeep Singh Avatar answered Oct 04 '22 02:10

Jasdeep Singh


In my case was needed to add the crypt_method

"stream_context" => stream_context_create(
        array(
            'ssl' => array(
                'verify_peer'       => true,
                'verify_peer_name'  => true,
                'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
            )
        )
    )
like image 38
Neemias Santos Avatar answered Oct 04 '22 04:10

Neemias Santos


In my case "stream_context" did the magic, i've just added the code :

`"stream_context" => stream_context_create(
   array(
      'ssl' => array(
           'verify_peer'       => false,
           'verify_peer_name'  => false,
      )
   )
)`
like image 30
mehdigriche Avatar answered Oct 04 '22 02:10

mehdigriche