RemoteRegistrationInformationService Class |
All methods need an UserDTO as input - username, password MD5 encrypted and client-ipadress is madatory.
All methods need a format as input (json/xml) - result of request is delivered on format selected.
Namespace: OfvVehicleData.Service
public class RemoteRegistrationInformationService
The RemoteRegistrationInformationService type exposes the following members.
| Name | Description | |
|---|---|---|
| RemoteRegistrationInformationService | Initializes a new instance of the RemoteRegistrationInformationService class |
| Name | Description | |
|---|---|---|
| ChassisNoSearch |
Chassis number search for vehicle.
Returns object with registration-, eu-control-, owner-information and list of similar vehicles presented to marked when vehicle was new. | |
| RegNoSearch |
Registration number search for vehicle.
Returns object with registration-, eu-control-, owner-information and list of similar vehicles presented to marked when vehicle was new. |
Below is a simple example, that shows how to call the service RegNoSearch(UserDTO, String, Int32, String).
function runRegNoSearch() { var userObject = { "username": "your username", "password": "md5 password", "ipAddress": "your ip address" }; var url = "https://remoteregno.kjoretoydata.no/RemoteRegNoInformation/RegNoSearch?format=json"; var input = { "user": userObject, "searchString": "AB12345", "vehicleGroup": "101" }; $.ajax({ type: "POST", url: url, data: JSON.stringify(input), processData: true, contentType: "application/json; charset=utf-8", dataType: "json", success: function (response) { alert('Result: ' + response); } , error: function (request, status, error) { alert('Error:' + request.status + ',' + request.statusText + ',' + request.responseText); } }); }
// ****************************************************************************************************** // Client method for registration number search // - user object must include username, password MD5 encrypted and client ipaddress // - vhg is not in use, but must be set to 101 // - searchstring is the registration number to search for and must be on form AB1234, AB01234 or AB12345 // // Copyright Opplysningsrådet for veitrafikken AS 2015 // ****************************************************************************************************** public DTO RegNoData(UserDTO user, int vhg, string searchString) { // Internal object InputDTO _input = new InputDTO() { user = user, searchString = searchString, vehicleGroup = vhg, data = false }; // Setup request var httpWebRequest = (HttpWebRequest)WebRequest.Create(ConfigurationManager.AppSettings["webservicehost"] + "/RegnoInformation/RegNoSearch?format=json"); httpWebRequest.ContentType = "text/json"; httpWebRequest.Method = "POST"; // Execute request using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { string json = JsonSerializer.Serialize<InputDTO>(_input); streamWriter.Write(json); streamWriter.Flush(); streamWriter.Close(); // Handle response and fill internal data object DTO with result // - object variables with same name as data-variable in response will automatically be set to value var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); dto = JsonSerializer.DeSerialize<DTO>(result); } } return dto; } // ****************************************************************************************************** // Helper class // // Copyright Opplysningsrådet for veitrafikken AS 2015 // ****************************************************************************************************** using System; using System.IO; using System.Text; using System.Runtime.Serialization.Json; namespace Ofv.Client.Helpers { public static class JsonSerializer { /// <summary> /// Common deserialization of json string to object structure /// </summary> /// <typeparam name="T"></typeparam> /// <param name="jsonString"></param> /// <returns></returns> public static T DeSerialize<T>(string jsonString) { MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonString)); try { DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T)); return (T)ser.ReadObject(ms); } catch (Exception e) { throw e; } finally { ms.Close(); } } /// <summary> /// Common serializer of object structure to json string /// </summary> /// <typeparam name="T"></typeparam> /// <param name="obj"></param> /// <returns></returns> public static string Serialize<T>(T obj) { MemoryStream stream = new MemoryStream(); try { DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T)); ser.WriteObject(stream, obj); stream.Position = 0; StreamReader sr = new StreamReader(stream); return sr.ReadToEnd(); } catch (Exception e) { throw e; } finally { stream.Close(); } } } }
/* OFV Registrationnumber service - search up registrationnumber - shows result or any error message The following example is tested in LINQPAD and can be implimented into .NET application Using the following: OfvService.DTO.Common OfvService.DTO.Comparison OfvService.DTO.Dummy OfvService.DTO.Filter OfvService.DTO.Login OfvService.DTO.Login.Logging OfvService.DTO.Login.Modules OfvService.DTO.Login.News OfvService.DTO.Login.Subscriptions OfvService.DTO.Notification OfvService.DTO.RegNo OfvService.DTO.Tax OfvService.DTO.Vehicle System.Net System.Runtime.Serialization.Json System.Security.Cryptography All code Copyright © 2015 Enoro AS, all rights reserved*/ /* RUN in LINQPAD*/ DTO dto = null; string resultStream = null; void Main() { // MD5 hash password string md5 = encode("password"); // Show encrypted password Debug.WriteLine(md5); // Create user object UserDTO user = new UserDTO() { username = "username", password = md5, ipAddress = "192.168.1.1" }; // AB12345 -> Non existing registrationnumber // FT12345 -> Existing registrationnumber DTO result = RegNoData(user, 101, "FT12345"); if(result.success) { // Show object name Debug.WriteLine(result.data); // Show json string Debug.WriteLine(resultStream); } else { // Show error description Debug.WriteLine(result.description); } } /* Call webservice - search for registrationumber*/ public DTO RegNoData(UserDTO user, int vhg, string searchString) { // Create input object InputDTO _input = new InputDTO() { user = user, searchString = searchString, vehicleGroup = vhg, data = false }; // SSL handling ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications); // Do request var httpWebRequest = (HttpWebRequest)WebRequest.Create("https://test-remoteregno.kjoretoydata.no/remoteregnoinformation/RegNoSearch?format=json"); httpWebRequest.ContentType = "text/json"; httpWebRequest.Method = "POST"; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { string json = JsonSerializer.Serialize<InputDTO>(_input); streamWriter.Write(json); streamWriter.Flush(); streamWriter.Close(); var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { resultStream = streamReader.ReadToEnd(); dto = JsonSerializer.DeSerialize<DTO>(resultStream); } } return dto; } /* MD5*/ public static String encode(string stringToEncode) { MD5 md5 = MD5.Create(); byte[] hash = md5.ComputeHash(Encoding.UTF8.GetBytes(stringToEncode)); var hexString = new StringBuilder(); foreach (byte byteFromHash in hash) { hexString.AppendFormat("{0:x2}", byteFromHash); } return hexString.ToString(); } /* SSL*/ public bool AcceptAllCertifications(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certification, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors) { return true; } /* Local input object*/ public class InputDTO { public UserDTO user { get; set; } public string searchString { get; set; } public int yearOffered { get; set; } public int vehicleGroup { get; set; } public bool data { get; set; } } /* JSON*/ public static class JsonSerializer { public static T DeSerialize<T>(string jsonString) { MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonString)); try { DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T)); return (T)ser.ReadObject(ms); } catch (Exception e) { throw e; } finally { ms.Close(); } } public static string Serialize<T>(T obj) { MemoryStream stream = new MemoryStream(); try { DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T)); ser.WriteObject(stream, obj); stream.Position = 0; StreamReader sr = new StreamReader(stream); return sr.ReadToEnd(); } catch (Exception e) { throw e; } finally { stream.Close(); } } }
800;Ikke gyldig kjennemerke => Wrong format on registration number (AA1234, AA01234, AA12345, A-00123, A-01234, A-12345 or A-123456.)
802;Kjennemerke ble ikke funnet. => Registration number not found
810;Ikke gyldig karosseri nummer => Wrong format on VIN (min. 9 and max. 17 long)
811;Karosseri nummer ble ikke funnet. => VIN not found
999;Systemfeil: {0} => System failure