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 | using System; using System.Collections.Generic; using System.Net; using System.Net.Http; using System.Net.Http.Headers; using System.Web; namespace Examples.CSharp.Rest { /// <summary> A REST example. </summary> public static partial class RestExample { /// <summary> Example of call with complex return type. </summary> /// <remarks> /// This example shows how to call the service which returns a complex data structure. /// </remarks> /// <param name="authToken"> The authentication token. </param> public static void CallWithComplexReturnType( string authToken) { // Create parameter query as expected by the TecRMI REST API var parameterQuery = HttpUtility.ParseQueryString( string .Empty); parameterQuery.Add( "LanguageCode" , "en" ); parameterQuery.Add( "CountryCode" , "GB" ); parameterQuery.Add( "TypeId" , "13494" ); parameterQuery.Add( "ItemMpId" , "244" ); parameterQuery.Add( "KorId" , "7" ); parameterQuery.Add( "BodyQualColId" , "0" ); parameterQuery.Add( "KindOfWorkTime" , KindOfWorkTimeData.DecimalWorkHours.ToString()); parameterQuery.Add( "ConsumerId" , "0" ); HttpResponseMessage response; // Create an HttpClient instance. using ( var serviceClient = new HttpClient()) { // 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. // Create URI { Port = -1, // suppress explicit port qualifier Path = "/rest/Times/WorkSteps" , Query = parameterQuery.ToString(), }; // Call service via GET. // Instead of using a UriBuilder, you can also pass a simple URI string // e.g. "/rest/common/languages?" + parameterQuery.ToString() response = serviceClient.GetAsync(uriBuilder.Uri).Result; } // response type LtWorkPos[] ltWorkPoses; 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 ; } } // Deserialise the content to predefined types representing // the response types of the TecRMI REST API. ltWorkPoses = response.Content.ReadAsAsync<LtWorkPos[]>().Result; } // Process the response foreach ( var workPos in ltWorkPoses) { Console.WriteLine( "- [{0}] {1} {2} ({3})" , workPos.WorkPosNo ?? string .Empty, workPos.ItemMpText, workPos.KorText, workPos.QualColText); Console.WriteLine( "\t- Exclusives:" ); foreach ( var excl in workPos.ExclusiveWorkPositions) { Console.WriteLine( "\t\t- [{0:0.00} h] {1} {2} ({3})" , excl.WorkTime, excl.ItemMpText, excl.KorText, excl.QualColText); } Console.WriteLine( "\t- Optional Exclusives:" ); foreach ( var opeExcl in workPos.OptionalExclusivePositions) { Console.WriteLine( "\t\t- [{0:0.00} h] {1} {2} ({3})" , opeExcl.WorkTime, opeExcl.ItemMpText, opeExcl.KorText, opeExcl.QualColText); } } } } /// <summary> /// Represents a work position for labour times part of the AuDaLib /// which contains all necessary information for selecting a work position for calculation. /// </summary> public class LtWorkPos : WorkPosData { /// <summary> /// Gets or sets the number of the work position. /// </summary> /// <value> /// The work position number. /// </value> public string WorkPosNo { get ; set ; } /// <summary> /// Gets or sets a collection of exclusive work positions. /// </summary> /// <remarks> /// This collection is only for your information and contains the values from which the main labour times work position are composed. /// </remarks> /// <value> /// The exclusive work positions. /// </value> public List<WorkPosData> ExclusiveWorkPositions { get ; set ; } /// <summary> /// Gets or sets a collection of optional exclusive work positions. These are optional additional labour times work positions /// which can only be selected in combination with its main labour times work position. /// </summary> /// <value> /// The optional exclusive positions. /// </value> public List<LtExclWorkPos> OptionalExclusivePositions { get ; set ; } /// <summary> /// Gets or sets a value indicating whether access to this generic work position is denied. /// </summary> /// <value> /// <c>true</c> if this generic work position is locked; otherwise, <c>false</c>. /// </value> public bool IsLocked { get ; set ; } } /// <summary> /// Represents an exclusive work position for labour times. The selected main work position is /// a composition of all the exclusive work positions. /// </summary> public class LtExclWorkPos { /// <summary> /// Gets or sets the id of the work position. /// </summary> /// <value> /// The work position id. /// </value> public int WorkId { get ; set ; } /// <summary> /// Gets or sets the text of the work position. /// </summary> /// <value> /// The work position text. /// </value> public string WorkText { get ; set ; } /// <summary> /// Gets or sets the text of the qualifier collection. /// </summary> /// <value> /// The qualifier collection text. /// </value> public string QualColText { get ; set ; } /// <summary> /// Gets or sets the text of the item mount position. /// </summary> /// <value> /// The item mount position text. /// </value> public string ItemMpText { get ; set ; } /// <summary> /// Gets or sets the text of the kind of repair. /// </summary> /// <value> /// The kind of repair text. /// </value> public string KorText { get ; set ; } /// <summary> /// Gets or sets the image of the kind of repair. /// </summary> /// <value> /// The kind of repair image. /// </value> public string KorImage { get ; set ; } /// <summary> /// Gets or sets the work time. /// </summary> /// <value> /// The work time. /// </value> public decimal WorkTime { get ; set ; } /// <summary> /// Gets or sets an enum value indicates which unit the work time in the result should have. /// </summary> /// <value> /// The kind of work time data. /// </value> public KindOfWorkTimeData KindOfWorkTimeData { get ; set ; } /// <summary> /// Gets or sets a value indicating whether the work time of this instance is only for reference. /// </summary> /// <value> /// <c>true</c> if this instance is only for reference; otherwise, <c>false</c>. /// </value> public bool IsOnlyForReference { get ; set ; } /// <summary> /// Gets or sets a value indicating whether the work time of this instance is defined by TecRMI. /// </summary> /// <value> /// <c>true</c> if the work time of this instance is adc time; otherwise, <c>false</c>. /// </value> public bool IsTecRmiTime { get ; set ; } /// <summary> /// Gets or sets a value indicating whether the work time of this instance is a net work time. /// </summary> /// <value> /// <c>true</c> if this instance is composite time; otherwise, <c>false</c>. /// </value> public bool IsCompositeTime { get ; set ; } } /// <summary> /// Represents an optional exclusive work position for a labour times work position /// which can only be selected in combination with its main labour times work position. /// </summary> public class LtOptExclWorkPos : WorkPosData { /// <summary> /// Gets or sets the number of the work position. /// </summary> /// <value> /// The work position number. /// </value> public string WorkPositionNo { get ; set ; } } /// <summary> /// Specifies the base class of a work position. /// </summary> public class WorkPosData { /// <summary> /// Gets or sets the id of the item mount position. /// </summary> /// <value> /// The item mount position id. /// </value> public int ItemMpId { get ; set ; } /// <summary> /// Gets or sets the id of the kind of repair. /// </summary> /// <value> /// The kind of repair id. /// </value> public int KorId { get ; set ; } /// <summary> /// Gets or sets the id of the qualifier collection. /// </summary> /// <value> /// The qualifier collection id. /// </value> public int QualColId { get ; set ; } /// <summary> /// Gets or sets the id of the work position. /// </summary> /// <value> /// The work position id. /// </value> public int WorkId { get ; set ; } /// <summary> /// Gets or sets the text of the work position. /// </summary> /// <value> /// The work position text. /// </value> public string WorkText { get ; set ; } /// <summary> /// Gets or sets the text of the qualifier collection. /// </summary> /// <value> /// The qualifier collection text. /// </value> public string QualColText { get ; set ; } /// <summary> /// Gets or sets the text of the item mount position. /// </summary> /// <value> /// The item mount position text. /// </value> public string ItemMpText { get ; set ; } /// <summary> /// Gets or sets the text of the kind of repair. /// </summary> /// <value> /// The kind of repair text. /// </value> public string KorText { get ; set ; } /// <summary> /// Gets or sets the image of the kind of repair. /// </summary> /// <value> /// The kind of repair image. /// </value> public string KorImage { get ; set ; } /// <summary> /// Gets or sets the work time. /// </summary> /// <value> /// The work time. /// </value> public decimal WorkTime { get ; set ; } /// <summary> /// Gets or sets an enum value indicates which unit the work time in the result should have. /// </summary> /// <value> /// The kind of work time data. /// </value> public KindOfWorkTimeData KindOfWorkTimeData { get ; set ; } /// <summary> /// Gets or sets a value indicating whether the work time of this instance is only for reference. /// </summary> /// <value> /// <c>true</c> if this instance is only for reference; otherwise, <c>false</c>. /// </value> public bool IsOnlyForReference { get ; set ; } /// <summary> /// Gets or sets a value indicating whether the work time of this instance is defined by TecRMI. /// </summary> /// <value> /// <c>true</c> if the work time of this instance is TecRMI time; otherwise, <c>false</c>. /// </value> public bool IsTecRmiTime { get ; set ; } /// <summary> /// Gets or sets a value indicating whether the work time of this instance is a net work time. /// </summary> /// <value> /// <c>true</c> if this instance is composite time; otherwise, <c>false</c>. /// </value> public bool IsCompositeTime { get ; set ; } } /// <summary> /// Enum <c>KindOfWorkTimeData</c> specifies the kinds of work time data. /// In other words this enumeration determines the unit a work time has. /// </summary> public enum KindOfWorkTimeData { /// <summary> /// The work time is displayed in decimal work hours. /// </summary> DecimalWorkHours = 0, /// <summary> /// The work time is displayed in manufacturer work time units. /// </summary> ManufacturerWorkPositions = 1 } } |
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 | // Initialize web service parameter JSONObject param = new JSONObject(); param.put( "LanguageCode" , "en" ); param.put( "CountryCode" , "GB" ); param.put( "TypeId" , 13494 ); param.put( "ItemMpId" , 244 ); param.put( "KorId" , 7 ); param.put( "BodyQualColId" , 0 ); param.put( "KindOfWorkTime" , "DecimalWorkHours" ); param.put( "ConsumerId" , 12 ); // 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 | // Set parameters var languageCode = 'en' , countryCode = 'GB' , typeId = 13494, itemMpId = 244, korId = 7, bodyQualColId = 0, kindOfWorkTime = 'DecimalWorkHours' , consumerId = 12; // Build url query string var query = '?languageCode=' + languageCode + '&countryCode=' + countryCode + '&typeId=' + typeId + '&itemMpId=' + itemMpId + '&korId=' + korId + '&bodyQualColId=' + bodyQualColId; + '&kindOfWorkTime=' + kindOfWorkTime + '&consumerId=' + consumerId; // Send HTTP request var xmlHttp = new XMLHttpRequest(); xmlHttp.open( 'GET' , url + query, false ); xmlHttp.setRequestHeader( 'Content-type' , 'application/json;charset=UTF-8' ); xmlHttp.setRequestHeader( 'Accept' , 'applicationp/json' ); xmlHttp.setRequestHeader( 'Authorization' , authToken ); xmlHttp.send( null ); // 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 | $vars = array ( 'callback' => 'responsevalue' , 'LanguageCode' => 'de' , 'CountryCode' => 'de' , 'TypeId' => 13494, 'ItemMpId' => 244, 'KorId' => 7, 'BodyQualColId' => 0, 'KindOfWorkTime' => 'DecimalWorkHours' , 'ConsumerId' => '12' ); $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_RETURNTRANSFER, true); curl_setopt( $ch , CURLOPT_HTTPHEADER, $headers ); $output = curl_exec( $ch ); curl_close ( $ch ); var_dump(json_decode( $output )); |