示例#1
0
        public Emissions OBU1_GetVehicleEmissions(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))
                {
                    Emissions emissions = new Emissions();

                    emissions.CO    = client.Vehicle_getCOEmission(vehID);
                    emissions.CO2   = client.Vehicle_getCO2Emission(vehID);
                    emissions.HC    = client.Vehicle_getHCEmission(vehID);
                    emissions.Noise = client.Vehicle_getNoiseEmission(vehID);
                    emissions.NOx   = client.Vehicle_getNOxEmission(vehID);
                    emissions.PMx   = client.Vehicle_getPMxEmission(vehID);

                    return(emissions);
                }
                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();
            }
        }