/// <summary> /// Deserializes response JSON object. /// </summary> /// <param name="json">String in JSON format.</param> /// <param name="knownTypes"> /// Types that may be present in the object graph. Can be null. /// </param> /// <returns> /// Deserialized object. /// </returns> public static T DeserializeResponse <T>(string json, IEnumerable <Type> knownTypes) { // validate response string if (String.IsNullOrEmpty(json)) { throw new SerializationException(Properties.Messages.Error_InvalidJsonResponseString); } T obj = default(T); // check if response string contains error data if (JsonProcHelper.IsFaultResponse(json)) { // deserialize error object GPFaultResponse errorObj = Deserialize <GPFaultResponse>(json); // create response object obj = Activator.CreateInstance <T>(); // set error data IFaultInfo fault = obj as IFaultInfo; if (fault != null) { fault.FaultInfo = errorObj.Error; } } else { // deserialize response object obj = Deserialize <T>(json, knownTypes, true); } return(obj); }
/// <summary> /// Validates ArcGIS REST service response. /// </summary> public static void ValidateResponse(object resp) { Debug.Assert(resp != null); IFaultInfo faultInfo = resp as IFaultInfo; Debug.Assert(faultInfo != null); if (faultInfo.IsFault) { throw CreateRestException(faultInfo); } }
/// <summary> /// Validates the specified REST service response. /// </summary> /// <param name="faultInfo">The REST service response to be validated.</param> /// <returns>An instance of the <see cref="CommunicationException"/> class representing /// REST service failure or null reference if there were no errors.</returns> private CommunicationException _ValidateResponse(IFaultInfo faultInfo) { if (faultInfo == null || !faultInfo.IsFault) { return(null); } var error = RestHelper.CreateRestException(faultInfo); Logger.Warning(error); return(new CommunicationException( error.Message, _serviceTitle, CommunicationError.Unknown, error)); }
/// <summary> /// Creates RestException object. /// </summary> public static RestException CreateRestException(IFaultInfo faultInfo) { Debug.Assert(faultInfo != null); Debug.Assert(faultInfo.IsFault); RestException ex = null; GPError error = faultInfo.FaultInfo; if (error != null) { ex = new RestException(error.Message, error.Code, error.Details); } else { ex = new RestException( Properties.Messages.Error_InvalidArcgisRestResponse); } return(ex); }