Example #1
0
        public double OBU1_GetVehicleSafetyDistance(string vehID, [FromBody] string address)
        {
            if (string.IsNullOrEmpty(address))
            {
                address = "http://127.0.0.1:8080/TRAAS_WS"; //default address
            }
            TraasReference.ServiceImplClient client = new TraasReference.ServiceImplClient();
            client.Endpoint.Address = new EndpointAddress(address);

            try
            {
                client.Open();
                if (isVehicleActive(address, vehID))
                {
                    double vehicleSafetyDistance = client.Vehicle_getMinGap(vehID);
                    return(vehicleSafetyDistance);
                }
                throw new FaultException("Vehicle with that ID is not in simulation.");
            }
            catch (FaultException e)
            {
                client.Abort();
                throw new FaultException(e.Message);
            }
            catch (Exception e)
            {
                throw new FaultException(e.InnerException.ToString());
            }
            finally
            {
                client.Close();
            }
        }