private static AzureFunctionCheckResponse ParseResponseObjectsOpStatusResponse(HttpWebResponse httpWebResponse) { //try //{ if (httpWebResponse.StatusCode == HttpStatusCode.OK) { //if (httpWebResponse.ContentType==) DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(AzureFunctionCheckResponse)); if (httpWebResponse.ContentLength > int.MaxValue) { throw new IndexOutOfRangeException(String.Format("Response From Web Service Exceeds {0}", int.MaxValue)); } // WWB: Read The Data From The Response Stream int length = (int)httpWebResponse.ContentLength; byte[] data = new byte[length]; using (Stream responseStream = httpWebResponse.GetResponseStream()) { responseStream.Read(data, 0, length); } // WWB: In A Memory Stream Convert the Json using (MemoryStream stream = new MemoryStream(data)) { var response = serializer.ReadObject(stream) as AzureFunctionCheckResponse; // WWB: Check The Response For Errors if (response.WindowsAzureStatus != AzureFunctionCheckResponseStatus.Success) { var exception = new WebServiceException<AzureFunctionCheckResponseStatus>() { Status = response.WindowsAzureStatus }; throw exception; } return response; } } else { AzureFunctionCheckResponse ErrorResponse = new AzureFunctionCheckResponse() { WindowsAzureStatus = AzureFunctionCheckResponseStatus.IllegalResponse, FunctionCheckResult = null, RequestId = String.Empty, FunctionName = String.Empty }; return ErrorResponse; } }
/// <summary> /// Callback from Request For Upating Status /// </summary> /// <param name="asynchronousResult">Aync Response From Request</param> private static void HttpWebResponseUpdateDeploymentCallback(IAsyncResult asynchronousResult) { // State of request is asynchronous. InternalRequestState<UpdateDeploymentStatusRequest> requestState = (InternalRequestState<UpdateDeploymentStatusRequest>)asynchronousResult.AsyncState; // WWB: Stop The Time Out Timer -- Request Has Completed requestState.HttpWebRequestTimer.SafeStop(); try { HttpWebRequest httpWebRequest = requestState.HttpWebRequest; using (HttpWebResponse httpWebReponse = (HttpWebResponse)httpWebRequest.EndGetResponse(asynchronousResult)) { // Parse response object //requestState.Callback(new WebServiceResponse<UpdateDeploymentStatusRequest>(requestState.ExternalRequestState)); // //requestState.Callback(new WebServiceResponse<DeploymentReinstanceRequest>(requestState.ExternalRequestState)); if (httpWebReponse.ContentType.Contains("application/json")) { AzureFunctionCheckResponse response = ParseResponseObjectsOpStatusResponse(httpWebReponse); ((UpdateDeploymentStatusRequest)requestState.ExternalRequestState).ResultResponse = response; //if (response.FunctionCheckResult != null) //{ // ((UpdateDeploymentStatusRequest)requestState.ExternalRequestState).Result = response.FunctionCheckResult; //} requestState.Callback(new WebServiceResponse<UpdateDeploymentStatusRequest>(requestState.ExternalRequestState)); } else { AzureFunctionCheckResponse ErrorResponse = new AzureFunctionCheckResponse() { WindowsAzureStatus = AzureFunctionCheckResponseStatus.IllegalResponse }; } } } catch (Exception exception) { // WWB: All Exception Are Handled By The Exception Callback if (requestState.ExceptionCallback == null) { throw; } else { // WWB: Package Up A Exception Response Object ExceptionReponse<UpdateDeploymentStatusRequest> response = new ExceptionReponse<UpdateDeploymentStatusRequest>() { Exception = exception, Request = requestState.ExternalRequestState }; // Call The Exception Call Back With the Exception Response To Report Exceptions To The Caller requestState.ExceptionCallback(new WebServiceResponse<ExceptionReponse<UpdateDeploymentStatusRequest>>(response)); } } }