JahStation
JahStation

Reputation: 917

simple php soap client helps

I tried to combine several post and php manual page but i didn't well understand how to make a simple soap request using a php soap client.

this is the soap example that i've to refer:

http://<endpoint>/ourServer/services/spPushDataServicePort.svc
Encoding: UTF-8
Http-Method: POST
Content-Type: text/xml; charset=UTF-8
Headers: {connection=[Keep-Alive], Content-Length=[789], content-type=[text/xml; charset=UTF-8], host=[urbelog.tilab.com], SOAPAction=["pushData"], user-agent=[Axis2], via=[1.1 urlXXX], x-forwarded-for=[Url2Ip], x-forwarded-host=[urlXXX], x-forwarded-server=[urlXXX]}
Payload: <?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
  <soapenv:Body>
   <ns1:outData xmlns:ns1="http://serverYYY">
    <vin>M55</vin>
    <serviceProvider>URBELOG</serviceProvider>
    <codeFunction>FLEET</codeFunction> 
    <date>2016-10-19T11:06:20.000+00:00</date>
    <groups>
     <name>GPS_DATA</name>
     <params>
      <name>LATITUDE</name>
      <value>45.086666</value>
     </params>
     <params>
      <name>LONGITUDE</name>
      <value>9.29</value>
     </params>
     <params>
      <name>TIMESTAMP</name>
      <value>2016-10-19 13:06:20</value>
     </params>
     <params>
      <name>ODOMETER</name>
       <value>483734.56</value>
     </params>
    </groups>
   </ns1:outData>
  </soapenv:Body>
</soapenv:Envelope>

This is what i wrote until now: class sendData {

    function __construct($vin, $serviceProvider,$codeFunction, $date, $lat, $long, $timeStamp, $mt)
    {
        $this->vin = $vin;
        $this->serviceProvider = $serviceProvider;
        $this->codeFunction=$codeFunction;
        $this->date = $date;
        $this-> groups= array('name'=>"GPS_DATA",
                                array('params'=>['LATITUDE'=>$lat]),
                                array('params'=>['LONGITUDE'=>$long]),
                                array('params'=>['TIMESTAMP'=>$timeStamp]),
                                array('params'=>['ODOMETER'=>$mt]));

    }
}

/* Initialize webservice with your WSDL */
$client = new SoapClient("http://<endpoint>/ourServer/services/spPushDataServicePort.svc");

/* Set your parameters for the request */
$params=new sendData("uno","due","3","4","5","6","7","8");

/* Invoke webservice method with your parameters, in this case: Function1 */
$response = $client->__soapCall(?????, $params);   


var_dump($response);

my questions are:

Upvotes: 1

Views: 783

Answers (1)

Kris Peeling
Kris Peeling

Reputation: 1025

The first parameter of __soapCall is the function name you want to call, so in this case it should be "pushData" (The example indicates SOAPAction=["pushData"])

The second parameter of __soapCall takes an array, so the right way to passing params is:

$response = $client->__soapCall("pushData", array($params));

A better and more cleaner approach might be to do it this way:

$response = $client->pushData($params);

To get more information from the web service about the methods and data types you need to use, you can use:

var_dump($client->__getFunctions());
var_dump($client->__getTypes());

Here's more info about the SoapClient class and what you can do with it.

Upvotes: 1

Related Questions