The following assembly references are required:
- mscorlib
- System
- System.Core
- System.Net.Http
- System.Net.Http.Formatting
- System.Web
The following assembly references are required:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 | using System; using System.Collections.Generic; using System.Net; using System.Net.Http; using System.Net.Http.Headers; namespace Examples.CSharp.Rest { /// <summary> A rest example. </summary> public static partial class RestExample { /// <summary> Example of call with complex parameter type. </summary> /// <remarks> /// This example shows how to call the service by submitting a complex data structure as /// parameters via POST. /// </remarks> /// <param name="authToken"> The authentication token. </param> public static void CallWithComplexParameterType( string authToken) { // Create the method specific message object. // Use the predefined types representing the parameters of the TecRMI REST API. var msg = new MakeListMsg { LanguageCode = "en" , CountryCode = "GB" , ComponentTypeIdFilter = null , ModuleFilter = VtModulFilter.Lt, RangeNameFilter = "LEON" , ShowBike = false , ShowCar = true , ShowTruck = false , TypeNameFilter = "TSI" , // complex parameter AddInfoKeyFilter = new List<AddInfoKeyFilterParameter> { new AddInfoKeyFilterParameter { // filter for build in year AddInfoKeyId = 3, AddInfoKeyFilterValue = "200711" , }, new AddInfoKeyFilterParameter { // filter for power in kW AddInfoKeyId = 5, AddInfoKeyFilterValue = "92" , }, new AddInfoKeyFilterParameter { // filter for capacity in ccm AddInfoKeyId = 6, AddInfoKeyFilterValue = "1390" , }, new AddInfoKeyFilterParameter { // filter for VIN AddInfoKeyId = -8, AddInfoKeyFilterValue = "VSSZZZ1PZCR073037" , } }, }; HttpResponseMessage response; // Create an HttpClient instance. using ( var serviceClient = new HttpClient { BaseAddress = new Uri( "https://rmi-services.tecalliance.net" ) }) { // Set the media type for the response either JSON ("application/json") or XML ("application/xml") // If not set the default response will be "application/json". serviceClient.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue( "application/json" )); // Set the authentication token, the user agent and the origin. // These have to be the same for all requests. serviceClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue( "TecRMI" , authToken); // Set the user agent to a value that indentifies your client application. If your client application is also // a web application the user agent of the original request could be passed to identify the user's browser // e.g. new ProductInfoHeaderValue(HttpContext.Current.Request.UserAgent). serviceClient.DefaultRequestHeaders.UserAgent.Add( new ProductInfoHeaderValue( "Examples.Csharp.Rest" , "1.0" )); // Set the origin to a value that indentifies your client application. If your client application is also // a web application the user agent of the original request could be passed (HttpContext.Current.Request.UserAgent) // to identify the user's browser. // Call service via POST content. response = serviceClient.PostAsJsonAsync( "/rest/vehicletree/makelist" , msg).Result; } // response type VtMake[] makes; using (response) { // handle the error if necessary. if (!response.IsSuccessStatusCode) { switch (response.StatusCode) { case HttpStatusCode.Unauthorized: // 401 Console.WriteLine( "Not Authenticated!" ); return ; case HttpStatusCode.Forbidden: // 403 Console.WriteLine( "Unsufficient permissions!" ); return ; case HttpStatusCode.InternalServerError: // 500 Console.WriteLine( "An error occured!" ); return ; default : Console.WriteLine( "Unexpected response!" ); return ; } } makes = response.Content.ReadAsAsync<VtMake[]>().Result; } // Process the response Console.WriteLine( " Id | IsLocked | InfoDataExists | Name" ); Console.WriteLine( "------------+----------+----------------+------------" ); foreach ( var make in makes) { Console.WriteLine( " {0,10} | {1,-8} | {2,-14} | {3}" , make.MakeId, make.IsLocked, make.InfoDataExists, make.MakeName); } } } /// <summary> /// Class <see cref="MakeListMsg"/> contains the properties which are necessary to call web service methods MakeList(MakeListMsg). /// </summary> public class MakeListMsg { /// <summary> /// Gets or sets the module filter. /// </summary> /// <remarks> /// Possible values are: /// <dl> /// <dt>None</dt> /// <dd>No module filtering</dd> /// <dt>Ad</dt> /// <dd>Only vehicles which have data in the adjustment data module.</dd> /// <dt>Coo</dt> /// <dd>Only vehicles which have new data in the cost of ownership module since the last database update.</dd> /// <dt>Coo New</dt> /// <dd>Only vehicles which have data in the new cost of ownership module.</dd> /// <dt>Di</dt> /// <dd>Only vehicles which have data in the diagnose module.</dd> /// <dt>Ctrl</dt> /// <dd>Only vehicles which have data in the control module.</dd> /// <dt>Lt</dt> /// <dd>Only vehicles which have data in the labour times module.</dd> /// <dt>Md</dt> /// <dd>Only vehicles which have data in the maintenance data module.</dd> /// <dt>Sos</dt> /// <dd>Only vehicles which have data in the Sos module.</dd> /// <dt>Tm</dt> /// <dd>Only vehicles which have data in the technical manuals module.</dd> /// <dt>Td</dt> /// <dd>Only vehicles which have data in the tyre data module.</dd> /// <dt>Wd</dt> /// <dd>Only vehicles which have data in the wiring data module.</dd> /// </dl> /// </remarks> /// <value> /// The module filter. /// </value> public VtModulFilter ModuleFilter { get ; set ; } /// <summary> /// Gets or sets the filter for the vehicle range names. An empty string means no range filtering. /// </summary> /// <value> /// The filter for the range names. /// </value> public string RangeNameFilter { get ; set ; } /// <summary> /// Gets or sets the filter for the vehicle type names. An empty string means no type filtering. /// </summary> /// <value> /// The filter for the type names. /// </value> public string TypeNameFilter { get ; set ; } /// <summary> /// Gets or sets the filter after additional information like fuel typ, national vehicle number etc. /// </summary> /// <value> /// The filter after additional informations. /// </value> public List<AddInfoKeyFilterParameter> AddInfoKeyFilter { get ; set ; } /// <summary> /// Gets or sets the component type id filter. Passing <c>null</c> means no component type id filtering. /// </summary> /// <value> /// The component type id filter. /// </value> public int ? ComponentTypeIdFilter { get ; set ; } /// <summary> /// Gets or sets a value indicating whether cars are included in the result. /// </summary> /// <value> /// <c>true</c> if cars should be included in the result; otherwise, <c>false</c>. /// </value> public bool ShowCar { get ; set ; } /// <summary> /// Gets or sets a value indicating whether trucks and light commercial vehicles are included in the result. /// </summary> /// <value> /// <c>true</c> if trucks and light commercial vehicles should be included in the result; otherwise, <c>false</c>. /// </value> public bool ShowTruck { get ; set ; } /// <summary> /// Gets or sets a value indicating whether motorbikes are included in the result. /// </summary> /// <value> /// <c>true</c> if motorbikes should be included in the result; otherwise, <c>false</c>. /// </value> public bool ShowBike { get ; set ; } /// <summary> /// Gets or sets the 2-letter international country code as defined by ISO 3166-1. /// </summary> /// <value> /// The ISO country code. /// </value> public string CountryCode { get ; set ; } /// <summary> /// Gets or sets the 2-letter international language code as defined by ISO 639-1. /// </summary> /// <value> /// The ISO language code. /// </value> public string LanguageCode { get ; set ; } } /// <summary> /// Class <c>AddInfoKeyFilterParameter</c> represents an additional information key filter /// parameter. This class is used in order to filter vehicles and components by additional /// information keys. /// </summary> public class AddInfoKeyFilterParameter { /// <summary> /// Gets or sets the additional information key id. The id is negative if the additional information key represents a component. /// </summary> /// <value> /// The additional information key id. /// </value> public int AddInfoKeyId { get ; set ; } /// <summary> /// Gets or sets the additional information key filter value. /// </summary> /// <value> /// The additional information key filter value. /// </value> public string AddInfoKeyFilterValue { get ; set ; } } /// <summary> Values that represent VtModulFilter. </summary> public enum VtModulFilter { /// <summary> /// No module filter is set. /// </summary> None = 0, /// <summary> /// The filter for module adjustment data (Ad) is set. /// </summary> Ad = 1, /// <summary> /// The filter for module cost of ownership (Coo) is set. /// </summary> Coo = 2, /// <summary> /// The filter for the module new cost of ownership (COO-New) is set. /// </summary> CooNew = 3, /// <summary> /// The filter for module control (Ctrl) is set. /// </summary> Ctrl = 4, /// <summary> /// The filter for module diagnose (Di) is set. /// </summary> Di = 5, /// <summary> /// The filter for module labour times (Lt) is set. /// </summary> Lt = 6, /// <summary> /// The filter for the module maintenance data (Md) is set. /// </summary> Md = 7, /// <summary> /// The filter for the module Sos is set. /// </summary> Sos = 8, /// <summary> /// The filter for the module technical manuals (Tm) is set. /// </summary> Tm = 9, /// <summary> /// The filter for the module tyre data (Td) is set. /// </summary> Td = 10, /// <summary> /// The filter for the module wiring data (Wd) is set. /// </summary> Wd = 11, /// <summary> /// The filter for the module TecNotes is set. /// </summary> Notes = 12, /// <summary> /// The filter for the module comfort wiring data (CWD) is set. /// </summary> Cwd = 13, /// <summary> /// The filter for the module fuse and relays (Fr) is set. /// </summary> Fr = 14, /// <summary> /// The filter for the module component location (Pp) is set. /// </summary> Pp = 15, /// <summary> /// The filter for the module graphical selection (Bg) is set. /// </summary> Bg = 16, /// <summary> /// The filter for the module vin filter is set. /// </summary> VIN = 17, /// <summary> /// An enum constant representing all modules are allowed. /// </summary> All = -1 } /// <summary> /// Class <c>VtMake</c> represents a vehicle manufacturer (make). In the vehicle tree hierarchy, makes are on the topmost level. /// </summary> public class VtMake { /// <summary> /// Gets or sets the id of the vehicle manufacturer. /// </summary> /// <value> /// The make id. /// </value> public int MakeId { get ; set ; } /// <summary> /// Gets or sets the name of the vehicle manufacturer. /// </summary> /// <value> /// The name of the make. /// </value> public string MakeName { get ; set ; } /// <summary> /// Gets or sets a value indicating whether access to this vehicle manufacturer is denied. /// </summary> /// <value> /// <c>true</c> if this make is locked; otherwise, <c>false</c>. /// </value> public bool IsLocked { get ; set ; } /// <summary> /// Gets or sets a value indicating whether there are information data existing for this vehicle manufacturer. /// The portal database must be available to provide information data. /// </summary> /// <value> /// <c>true</c> if info data exists; otherwise, <c>false</c>. /// </value> public bool InfoDataExists { get ; set ; } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | // Initialize web service parameter JSONObject param = new JSONObject(); param.put( "LanguageCode" , "en" ); param.put( "CountryCode" , "GB" ); param.putOpt( "ComponentTypeIdFilter" , null ); param.put( "ModuleFilter" , "Lt" ); param.put( "RangeNameFilter" , "A3" ); param.put( "ShowBike" , false ); param.put( "ShowCar" , true ); param.put( "ShowTruck" , false ); param.put( "TypeNameFilter" , "2.0 TDI" ); JSONObject filter1 = new JSONObject(); filter1.put( "AddInfoKeyId" , 3 ); filter1.put( "AddInfoKeyFilterValue" , 2005 ); param.append( "AddInfoKeyFilter" , filter1); JSONObject filter2 = new JSONObject(); filter2.put( "AddInfoKeyId" , 5 ); filter2.put( "AddInfoKeyFilterValue" , 100 ); param.append( "AddInfoKeyFilter" , filter2); JSONObject filter3 = new JSONObject(); filter3.put( "AddInfoKeyId" , 6 ); filter3.put( "AddInfoKeyFilterValue" , 1968 ); param.append( "AddInfoKeyFilter" , filter3); // Build and initialize url // Open connection HttpURLConnection conn = (HttpURLConnection)url.openConnection(); // Set system parameter to allow setting the "Origin" HTTP header System.setProperty( "sun.net.http.allowRestrictedHeaders" , "true" ); // Set request headers conn.setRequestMethod( "POST" ); conn.setRequestProperty( "UserAgent" , "TecRMI-Java-Example" ); // optional conn.setRequestProperty( "Accept" , "application/json" ); conn.setRequestProperty( "Content-Type" , "application/json" ); conn.setUseCaches( false ); conn.setDoInput( true ); conn.setDoOutput( true ); // Set authentication token conn.setRequestProperty( "Authorization" , authToken); // Set POST content OutputStream out = conn.getOutputStream(); Writer writer = new OutputStreamWriter(out, "UTF-8" ); writer.write(param.toString()); writer.close(); out.close(); // Check connection if (conn.getResponseCode() != 200 ) { throw new IOException(conn.getResponseMessage()); } // Buffer the result into a string BufferedReader reader = new BufferedReader( new InputStreamReader(conn.getInputStream())); StringBuilder sb = new StringBuilder(); String line; while ((line = reader.readLine()) != null ) { sb.append(line); } // Close reader and connection reader.close(); conn.disconnect(); // Output result JSONArray result = new JSONArray(sb.toString()); System.out.println(result.toString( 2 )); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | // Set parameters var params = { LanguageCode: 'en' , CountryCode: 'GB' , ComponentTypeIdFilter: 6, ModuleFilter: 0, RangeNameFilter: 'A3' , ShowBike: 0, ShowCar: 1, ShowTruck: 0, TypeNameFilter: '2.0 TDI' , AddInfoKeyFilter: [ { AddInfoKeyId: 3, AddInfoKeyFilterValue: '200711' }, { AddInfoKeyId: 5, AddInfoKeyFilterValue: '92' }, { AddInfoKeyId: 6, AddInfoKeyFilterValue: '1390' }, { AddInfoKeyId: -8, AddInfoKeyFilterValue: 'VSSZZZ1PZCR073037' } ] }; // Send HTTP request var xmlHttp = new XMLHttpRequest(); xmlHttp.open( 'POST' , url, false ); xmlHttp.setRequestHeader( 'Content-type' , 'application/json;charset=UTF-8' ); xmlHttp.setRequestHeader( 'Accept' , 'applicationp/json' ); xmlHttp.setRequestHeader( 'Authorization' , authToken ); xmlHttp.send( JSON.stringify( params ) ); // Show response alert( xmlHttp.responseText ); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | $vars = array ( 'callback' => 'responsevalue' , 'LanguageCode' => 'de' , 'CountryCode' => 'de' , 'ShowBike' => 'true' , 'ShowCar' => 'true' , 'ShowTruck' => 'true' , 'ModuleFilter' => '6' , 'RangeNameFilter' => 'A3' , 'TypeNameFilter' => '2.0 TDI' , 'AddInfoKeyFilter' => array ( array ( 'AddInfoKeyId' => 3, 'AddInfoKeyFilterValue' => '2005' ), array ( 'AddInfoKeyId' => 5, 'AddInfoKeyFilterValue' => '100' ), array ( 'AddInfoKeyId' => 6, 'AddInfoKeyFilterValue' => '1968' ) ) ); $vars = urldecode(http_build_query( $vars )); $ch = curl_init(); $headers = array (); $headers [] = 'Accept: application/jsonp' ; $headers [] = 'Host: rmi-services.tecalliance.net' ; $headers [] = 'Content-Length: ' . strlen ( $vars ); $headers [] = 'Authorization: TecRMI ' . $_SESSION [ 'token' ]; curl_setopt( $ch , CURLOPT_POSTFIELDS, $vars ); //Post Fields curl_setopt( $ch , CURLOPT_POST, 1); curl_setopt( $ch , CURLOPT_PROXY, '127.0.0.1:8888' ); curl_setopt( $ch , CURLOPT_RETURNTRANSFER, true); curl_setopt( $ch , CURLOPT_HTTPHEADER, $headers ); $output = curl_exec( $ch ); curl_close ( $ch ); var_dump(json_decode( $output )); |