I have a problem when consuming web service soap with php

2

I have the following code to consume a soap web service with php,

class request {

    public $request;

    public function __construct() {
        $this->request = new data();
    }

}

class data {

    public $EntityCode = 10324;
    public $TicketId = 6610042;

}

$webService = "https://test1.e-collect.com/d_Express/webservice/eCollectWebservicesv2.asmx";
$wsdl = "https://test1.e-collect.com/d_Express/webservice/eCollectWebservicesv2.asmx?wsdl";
$customer = new SoapClient($wsdl, array('trace' => true, 'debug' => true));
$req = new request();

$request = new SoapVar($req, SOAP_ENC_OBJECT, 'request', 'http://www.avisortech.com/eCollectWebservices');
try {
    //$result=$customer->__soapCall('getTransactionInformation', new SoapParam($request,'request'));
    $result = $customer->getTransactionInformation(new SoapParam($request, 'request'));
} catch (Exception $exc) {
    echo $exc->getMessage();
}
var_dump($customer->__getLastRequest());
echo($result);

the captured exception gives the following message: Server was unable to process request. --- > Object reference not set to an instance of an object.

and when verifying the last request he tells me that he sent this:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.avisortech.com/eCollectWebservices" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <SOAP-ENV:Body>
        <ns1:getTransactionInformation xsi:type="ns1:request">
            <request>
                <EntityCode>10324</EntityCode>
                <TicketId>6610042</TicketId>
            </request>
        </ns1:getTransactionInformation>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

and I have an example that works on soapUi perfectly, which is as follows:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ecol="http://www.avisortech.com/eCollectWebservices">
   <soapenv:Header/>
   <soapenv:Body>
      <ecol:getTransactionInformation>
         <ecol:request>
            <ecol:EntityCode>10324</ecol:EntityCode>
            <ecol:TicketId>6610042</ecol:TicketId>
         </ecol:request>
      </ecol:getTransactionInformation>
   </soapenv:Body>
</soapenv:Envelope>

when doing the test with the xml generated with php does not work but the example yes, I do not know how to make it work for me. I would be very grateful

    
asked by Jonathan Casas 26.09.2017 в 05:41
source

1 answer

1

I already managed to solve it, in the following way. I was missing was to put each variable as SoapVar and ready I worked it

class request {

    public $request;

    public function __construct() {
        $this->request = new SoapVar(new data(), SOAP_ENC_OBJECT, null, 'ns1', 'GetTransactionInformationType', 'http://www.avisortech.com/eCollectWebservices');
    }

}

class data {

    public $EntityCode;
    public $TicketId;

    public function __construct() {
        $this->EntityCode = new SoapVar(10324, XSD_STRING, null, 'ns1', 'EntityCode', 'http://www.avisortech.com/eCollectWebservices');
        $this->TicketId = new SoapVar(6610042, XSD_STRING, null, 'ns1', 'TicketId', 'http://www.avisortech.com/eCollectWebservices');
    }

}

$webService = "https://test1.e-collect.com/d_Express/webservice/eCollectWebservicesv2.asmx";
$wsdl = "https://test1.e-collect.com/d_Express/webservice/eCollectWebservicesv2.asmx?wsdl";
$customer = new SoapClient($wsdl, array('trace' => true, 'debug' => true));
$req = new request();


$data = new SoapVar($req, SOAP_ENC_OBJECT, null, 'ns1', 'GetTransactionInformationType', 'http://www.avisortech.com/eCollectWebservices');
$request = new SoapParam($data, 'request');
$newTicketId = new SoapParam($EntityCode, 'TicketId');

try {
    //$result=$customer->__soapCall('getTransactionInformation', new SoapParam($request,'request'));
    //$result = $customer->getTransactionInformation($request);
    var_dump($result);
} catch (Exception $exc) {
    echo $exc->getMessage();
}
var_dump($customer->__getLastRequest());
echo($result);
    
answered by 26.09.2017 в 23:11