/// <summary> /// Returns the response stream by calling REST service. /// </summary> /// <param name="request">The request.</param> /// <returns>Response from REST service.</returns> public override byte[] GetResponseStream(HttpWebRequest request) { FaultHandler handler = new FaultHandler(this.context); byte[] receivedBytes = new byte[0]; try { // Check whether the retryPolicy is null. if (this.context.IppConfiguration.RetryPolicy == null) { // If yes then call the rest service without retry framework enabled. receivedBytes = GetRestServiceCallResponseStream(request); } else { // If no then call the rest service using the execute action of retry framework. this.context.IppConfiguration.RetryPolicy.ExecuteAction(() => { receivedBytes = GetRestServiceCallResponseStream(request); }); } } catch (WebException webException) { // System.Net.HttpWebRequest.Abort() was previously called.-or- The time-out // period for the request expired.-or- An error occurred while processing the request. bool isIps = false; if (this.context.ServiceType == IntuitServicesType.IPS) { isIps = true; } IdsException idsException = handler.ParseResponseAndThrowException(webException, isIps); if (idsException != null) { this.context.IppConfiguration.Logger.CustomLogger.Log(TraceLevel.Error, idsException.ToString()); CoreHelper.AdvancedLogging.Log(idsException.ToString()); throw idsException; } } finally { this.context.RequestId = null; } return(receivedBytes); }
/// <summary> /// Creates the Event Args for Exception/Fault responses from server. /// </summary> /// <param name="exception">The exception class.</param> /// <returns>Async CallCompletedEvent Arguments.</returns> private AsyncCallCompletedEventArgs CreateEventArgsForException(Exception exception) { AsyncCallCompletedEventArgs resultArguments = null; WebException webException = exception as WebException; if (webException != null) { bool isIps = false; if (this.context.ServiceType == IntuitServicesType.IPS) { isIps = true; } FaultHandler handler = new FaultHandler(this.context); IdsException idsException = handler.ParseResponseAndThrowException(webException, isIps); if (idsException != null) { this.context.IppConfiguration.Logger.CustomLogger.Log(TraceLevel.Error, idsException.ToString()); CoreHelper.AdvancedLogging.Log(idsException.ToString()); resultArguments = new AsyncCallCompletedEventArgs(null, idsException); } } else { IdsException idsException = exception as IdsException; if (idsException != null) { this.context.IppConfiguration.Logger.CustomLogger.Log(TraceLevel.Error, idsException.ToString()); CoreHelper.AdvancedLogging.Log(idsException.ToString()); resultArguments = new AsyncCallCompletedEventArgs(null, idsException); } else { this.context.IppConfiguration.Logger.CustomLogger.Log(TraceLevel.Error, idsException.ToString()); CoreHelper.AdvancedLogging.Log(idsException.ToString()); resultArguments = new AsyncCallCompletedEventArgs(null, new IdsException("Exception has been generated.", exception)); } } return(resultArguments); }
/// <summary> /// Returns the response by calling REST service. /// </summary> /// <param name="request">The request.</param> /// <returns>Response from REST service.</returns> public override string GetResponse(HttpWebRequest request) { FaultHandler handler = new FaultHandler(this.context); // Create a variable for storing the response. string response = string.Empty; try { // Check whether the retryPolicy is null. if (this.context.IppConfiguration.RetryPolicy == null) { // If yes then call the rest service without retry framework enabled. response = this.CallRestService(request); } else { // If no then call the rest service using the execute action of retry framework. this.context.IppConfiguration.RetryPolicy.ExecuteAction(() => { response = this.CallRestService(request); }); } if (request != null && request.RequestUri != null && request.RequestUri.Segments != null) { if (System.Array.IndexOf(request.RequestUri.Segments, "reports/") >= 0) { if (!response.StartsWith("{\"Report\":")) { response = "{\"Report\":" + response + "}"; } } } if (request != null && request.RequestUri != null && request.RequestUri.Segments != null) { if (System.Array.IndexOf(request.RequestUri.Segments, "taxservice/") >= 0) { //This if condition was added as Json serialization was failing for the FaultResponse bcoz of missing TaxService seriliazation tag on AnyIntuitObject in Fms.cs class if (!response.Contains("Fault")) { if (!response.StartsWith("{\"TaxService\":")) { response = "{\"TaxService\":" + response + "}"; } } } } } catch (RetryExceededException retryExceededException) { // System.Net.HttpWebRequest.Abort() was previously called.-or- The time-out // period for the request expired.-or- An error occurred while processing the request. bool isIps = false; if (this.context.ServiceType == IntuitServicesType.IPS) { isIps = true; } this.context.IppConfiguration.Logger.CustomLogger.Log(TraceLevel.Error, retryExceededException.ToString()); CoreHelper.AdvancedLogging.Log(retryExceededException.ToString()); throw; } catch (WebException webException) { // System.Net.HttpWebRequest.Abort() was previously called.-or- The time-out // period for the request expired.-or- An error occurred while processing the request. bool isIps = false; if (this.context.ServiceType == IntuitServicesType.IPS) { isIps = true; } IdsException idsException = handler.ParseResponseAndThrowException(webException, isIps); if (idsException != null) { this.context.IppConfiguration.Logger.CustomLogger.Log(TraceLevel.Error, idsException.ToString()); CoreHelper.AdvancedLogging.Log(idsException.ToString()); throw idsException; } } finally { this.context.RequestId = null; } if (this.context.ServiceType == IntuitServicesType.IPS) { // Handle errors here Utility.IntuitErrorHandler.HandleErrors(response); } else { // Check the response if there are any fault tags and throw appropriate exceptions. IdsException exception = handler.ParseErrorResponseAndPrepareException(response); if (exception != null) { throw exception; } } // Return the response. return(response); }