Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP SoapClient returns null even thought there was a response

Using the PHP SoapClient, I make a call to the WSDL at https://webservices-test.ede.de:9443/ibis/ws/WS_EXT_ELC?wsdl and I get the following xml response (as indicated by $soapclient->__last_response)

<?xml version='1.0' encoding='UTF-8'?><soap:Envelope xmlns:ede="http://ede.de/webservices" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Body><Response action="ELC" requestId="1" version="1.0"><created>2017-09-04T16:04:46.556+02:00</created><StatusInformation>OK</StatusInformation><StatusCode>0</StatusCode><Payload><SalesOrderSimulateConfirmation><Items><Item><ID>10</ID><ProductID>0003062700050</ProductID><Price>2.970</Price><PositionPrice>2.970</PositionPrice><PriceUnit>1</PriceUnit><QuantityUnit>ST</QuantityUnit><QuantityAvailable>1</QuantityAvailable><QuantityProfile>1</QuantityProfile><Currency>EUR</Currency><Services /><Schedules>Geplante Liefertermine:  1 ST in KW 36.2017;</Schedules><Remark /><DangerMaterial /></Item></Items></SalesOrderSimulateConfirmation></Payload></Response></soap:Body></soap:Envelope>

Nevertheless, the call to $soapclient->simulateOrder() returns null.

How do I get the PHP SoapClient to return an object instead of null?

Note: The xml I use for the soap call is generated manually by an override to SoapClient::__doRequest(). The code for the soap call looks like:

$soapClient = new SoapClient('https://webservices-test.ede.de:9443/ibis/ws/WS_EXT_ELC?wsdl', array(
    'cache_wsdl'   => WSDL_CACHE_NONE,
    'trace'        => true,
    'exceptions'   => true,
    'soap_version' => SOAP_1_2,
    'features'     => SOAP_SINGLE_ELEMENT_ARRAYS,
    'login' => '------', // cannot post here for security purposes
    'password' => '-----', // cannot post here for security purposes
    'stream_context' => (
        stream_context_create(array(
            'ssl' => array(
                'verify_peer' => false,
                'verify_peer_name' => false,
                'allow_self_signed' => true
              )
         ))
));
$result = $soapClient->simulateOrder();

No exceptions are thrown, but $result is null

like image 550
Yirmiyahu Fischer Avatar asked Sep 04 '17 14:09

Yirmiyahu Fischer


2 Answers

The problem is the SSL setup, the error that is thrown when I try to call your code on my server is as follows:

Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://webservices-test.ede.de:9443/ibis/ws/WS_EXT_ELC?wsdl' : failed to load external entity "https://webservices-test.ede.de:9443/ibis/ws/WS_EXT_ELC?wsdl" in /home/repojarilo/public_html/sc.php:22 Stack trace: #0 /home/repojarilo/public_html/sc.php(22): SoapClient->SoapClient('https://webserv...', Array) #1 {main} thrown in ... on line 22

I am assuming you are trying to get the code to work with a self signed certificate as indicated in your SSL array inside of the request, however it looks like the SoapClient is not paying attention to it and throwing an error anyway.

So my solution would be to either buy an SSL (very cheap now days, try sites such as namecheap etc...) or use something like https://letsencrypt.org/ to obtain an SSL that will allow your soap client to work correctly.

Lastly I noticed a typo, in your code one line before last you have )); which should read )));.

Koda

like image 177
Kodaloid Avatar answered Sep 28 '22 13:09

Kodaloid


The Problem is that SOAP needs a valid SSL-Certificate.

For an testing-server it's sometimes not worth the effort, so maybe this link help you to use a little workarround, to got your SOAP-Request working without need to create a fully-validated SSL-Certificat:

http://automationrhapsody.com/send-soap-request-over-https-without-valid-certificates/

like image 29
suther Avatar answered Sep 28 '22 12:09

suther