Used technologies and tools
Source code
<?php
// login data
$kodf = '****';
$username = '****';
$pass = '****';
$client = new \SoapClient('https://api.webdispecink.cz/code/WebDispecinkServiceNet.php?wsdl');
// array for list of cars
$cars = array();
// the _getCarsList () function returns also car registration number
$car_list = $client->_getCarsList($kodf, $username, $pass);
if (isset($car_list->item) &&
is_array($car_list->item))
{
foreach ($car_list->item as $car)
{
if ($car->disabled == 0)
{
$cars[$car->carid] = array(
'identifier' => $car->identifikator // car registration number
);
}
}
}
// last parameter empty - position and other details of all available cars under the specified user
$car_positions = $client->_getCarsIDPosition2($kodf, $username, $pass, '');
if (isset($car_positions->item) &&
is_array($car_positions->item))
{
foreach ($car_positions->item as $position)
{
if (isset($cars[$position->cd]))
{
$cars[$position->cd] += array(
'latitude' => (float)$position->Zs, // latitude
'longitude' => (float)$position->Zd, // longitude
'speed' => (int)$position->sd, // speed
'running' => (bool)$position->EE, // key voltage indicator (> 0 = started)
'tachometer' => (float)$position->Km, // odometer value
'direction' => (int)$position->ca, // driving direction
);
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>List of vehicles with details - API Webdispatching</title>
</head>
<body>
<ul>
<?php
foreach ($cars as $car_id => $car)
{
?>
<li>
<strong>Car #<?php echo htmlspecialchars($car_id); ?></strong>
<ul>
<li>Registration number: <?php echo $car['identifier']; ?></li>
<li>Mileage: <?php echo $car['tachometer']; ?> km</li>
<li>Position: <?php echo ($car['latitude'] == 0 && $car['longitude'] == 0) ? 'invalid' : ($car['latitude'] . ', ' . $car['longitude']); ?></li>
<li>Current speed: <?php echo $car['speed']; ?> km/h</li>
<li>Direction: <?php echo $car['direction']; ?></li>
<li>Started: <?php echo $car['running'] ? "Yes" : "No"; ?></li>
</ul>
</li>
<?php
}
?>
</ul>
</body>
</html>
Used technologies and tools
Source code
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import javax.xml.soap.*;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class ExampleList
{
// login data
private static final String KODF = "****";
private static final String USERNAME = "****";
private static final String PASS = "****";
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
Map<Integer, CarInfo> cars = new HashMap<>();
try
{
// create a connection for SOAP
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();
// calling parameters of function_getCarsList ()
Map<String, String>parametersCarList = new HashMap<>();
parametersCarList.put("kodf", KODF);
parametersCarList.put("username", USERNAME);
parametersCarList.put("pass", PASS);
// SOAP server URL
String url = "https://api.webdispecink.cz/code/WebDispecinkServiceNet.php?wsdl";
// create a request with parameter for calling the function _getCarsList ()
SOAPMessage soapRequestCarList = createSOAPRequest("_getCarsList", parametersCarList);
// calling the function_getCarsList () to get the car registration number
SOAPMessage soapResponseCarList = soapConnection.call(soapRequestCarList, url);
/*
Example of server response:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn://api.webdispecink.cz/webdisser_02">
<SOAP-ENV:Body>
<ns1:_getCarsListResponse>
<return>
<item>
<cargroupid>0</cargroupid>
<carid>1</carid>
<identifikator>1M5 76 86</identifikator>
...
</item>
...
</return>
</ns1:_getCarsListResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
*/
// get response body - tag content <SOAP-ENV:Body>
SOAPBody responseCarList = soapResponseCarList.getSOAPBody();
// element <ns1:_getCarsListResponse>
Node getAllCarsPositionResponse = responseCarList.getFirstChild();
// element <return>
Node returnContent = getAllCarsPositionResponse.getFirstChild();
// list of elements <item>
NodeList items = returnContent.getChildNodes();
int i, j;
// go through the returned car records
for (i = 0; i < items.getLength(); i++)
{
Node item = items.item(i);
NodeList data = item.getChildNodes();
// create a new object of car to store the acquired data
CarInfo car = new CarInfo();
// browse all items of one record
for (int k = 0; k < data.getLength(); k++)
{
// text item content
String content = data.item(k).getTextContent();
switch (data.item(k).getLocalName())
{
// unique vehicle identifier
case "carid":
car.id = Integer.parseInt(content);
break;
// car registration number
case "identifikator":
car.identifier = content;
break;
// is the vehicle being tracked?
case "disabled":
car.disabled = content.compareTo("1") == 0;
break;
}
}
// saves the car for later editing
cars.put(car.id, car);
}
// calling parameters of function _getCarsIDPosition2()
Map<String, String>parametersCarPosition = new HashMap<>();
parametersCarPosition.put("kodf", KODF);
parametersCarPosition.put("username", USERNAME);
parametersCarPosition.put("pass", PASS);
parametersCarPosition.put("carid_list", "");
// create a request with parameter for calling the function _getCarsIDPosition2()
SOAPMessage soapRequestCarPosition = createSOAPRequest("_getCarsIDPosition2", parametersCarPosition);
// calling the function _getCarsIDPosition2() function to get more data about the car
SOAPMessage soapResponseCarPosition = soapConnection.call(soapRequestCarPosition, url);
/*
Example of server response:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn://api.webdispecink.cz/webdisser_02">
<SOAP-ENV:Body>
<ns1:_getCarsIDPosition2Response>
<return>
<item>
<cd>17641</cd>
<Zs>49.599318</Zs>
<Zd>17.247634</Zd>
...
</item>
...
</return>
</ns1:_getCarsListResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
*/
// get response body - tag content <SOAP-ENV:Body>
SOAPBody responseCarPosition = soapResponseCarPosition.getSOAPBody();
// element <ns1:_getCarsIDPosition2>
Node getCarsIDPosition2Response = responseCarPosition.getFirstChild();
// element <return>
returnContent = getCarsIDPosition2Response.getFirstChild();
// browse elements <item>
items = returnContent.getChildNodes();
for (i = 0; i < items.getLength(); i++)
{
Node item = items.item(i);
NodeList data = item.getChildNodes();
CarInfo car = null;
// find a vehicle according a unique identifier
for (j = 0; j < data.getLength(); j++)
{
if (data.item(j).getLocalName().compareTo("cd") == 0)
{
int id = Integer.parseInt(data.item(j).getTextContent());
car = cars.get(id);
}
}
// if vehicle wasn't found by id, continue by next
if (car == null)
{
continue;
}
// browse all items of one record
for (j = 0; j < data.getLength(); j++)
{
// text item content
String content = data.item(j).getTextContent();
// skip empty content
if (content.isEmpty())
{
continue;
}
switch (data.item(j).getLocalName())
{
// latitude
case "Zs":
car.latitude = Float.parseFloat(content);
break;
// longitude
case "Zd":
car.longitude = Float.parseFloat(content);
break;
// speed
case "sd":
car.longitude = Integer.parseInt(content);
break;
// key voltage indicator (> 0 = started)
case "EE":
car.running = Boolean.parseBoolean(content);
break;
// odometer value
case "Km":
car.tachometer = Float.parseFloat(content);
break;
// driving direction
case "ca":
car.direction = Integer.parseInt(content);
break;
}
}
}
// closing the connection
soapConnection.close();
// list information about cars on the output
for (Entry<Integer, CarInfo> entry : cars.entrySet())
{
CarInfo car = entry.getValue();
// only watched cars
if (car.disabled == false)
{
System.out.println(car);
}
}
}
catch (Exception e)
{
System.err.println("Error occurred while handling SOAP Request.");
e.printStackTrace();
}
}
private static SOAPMessage createSOAPRequest(String functionName, Map<String, String> parameters) throws Exception
{
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
// SOAP Envelope
SOAPEnvelope envelope = soapPart.getEnvelope();
// SOAP Body
SOAPBody soapBody = envelope.getBody();
SOAPElement soapBodyElem = soapBody.addChildElement(functionName);
// adding parameters
for (Entry<String, String> entry : parameters.entrySet())
{
String key = entry.getKey();
String value = entry.getValue();
SOAPElement paramKodf = soapBodyElem.addChildElement(key);
paramKodf.addTextNode(value);
}
soapMessage.saveChanges();
return soapMessage;
}
}
public class CarInfo extends Object
{
public int id; // unique vehicle identifier
public String identifier; // car registration number
public float latitude; // latitude
public float longitude; // longitude
public int speed; // speed
public boolean running; // is the vehicle started?
public float tachometer; // odometer value
public int direction; // driving direction
public boolean disabled; // is the vehicle being tracked?
@Override
public String toString()
{
String pattern =
"Car #%d%n" +
"Car registration number: %s%n" +
"Speedometer: %f km\n" +
"Geographical location: %f, %f%n" +
"Current speed: %d km/h%n" +
"Direction: %d%n" +
"Started: %s%n";
String output = String.format(pattern, id, identifier, tachometer, latitude, longitude, speed, direction, running ? "Yes" : "No");
return output;
}
}
Used technologies and tools
Source code
using HISoftware.Webdispecink.Api;
using HISoftware.Webdispecink.Api.Types;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
WebdispecinkClientProxy proxy = new WebdispecinkClientProxy
{
Company = "xxxx", // <---- Write your company code
Username = "xxxxx", // <---- Write your username
Password = "xxxxx" // <---- Write your password
};
try
{
// Calling GetCarsList API
Task<IEnumerable<WDS_CarItem>> taskGetCarList = proxy.GetCarsListAsync();
WDS_CarItem[] listCars = taskGetCarList.Result.ToArray();
Console.WriteLine($"All cars from \"{proxy.Company}\" company:");
Console.WriteLine("-------------------------------------");
foreach (WDS_CarItem carItem in listCars)
{
Console.WriteLine($"License plate: {carItem.identifikator}, Car Id: {carItem.carid}");
}
}
catch (Exception ex)
{
Console.WriteLine($"Exception {ex.GetType().FullName} has been thrown!\nMessage: \"{ex.InnerException.Message}\"");
}
Console.ReadLine();
}
}
}