private void GetResponseCallback(IAsyncResult asynchronousResult)
        {
            try
            {
            HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
            System.Diagnostics.Debug.WriteLine("\t-- GOT REQUEST");

            HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);
            System.Diagnostics.Debug.WriteLine("\t-- GOT RESPONSE\n");

            System.Diagnostics.Debug.WriteLine("***RESPONSE\n Length: " + response.ContentLength.ToString());
            System.Diagnostics.Debug.WriteLine("\n\n***RESPONSE\n URI: " + response.ResponseUri.ToString());
            System.Diagnostics.Debug.WriteLine("\n\n***RESPONSE\n Status Description: " + response.StatusDescription.ToString());
            System.Diagnostics.Debug.WriteLine("\n");

            string responseString = "FAIL";

            CollabrifyResponse_PB resp_pb = new CollabrifyResponse_PB();
            Response_CreateSession_PB resp_list_pb = new Response_CreateSession_PB();

            //to read server response
            Stream streamResponse = response.GetResponseStream();
            try
            {
                resp_pb = Serializer.DeserializeWithLengthPrefix<CollabrifyResponse_PB>(streamResponse, PrefixStyle.Base128, 0);

                responseString = resp_pb.success_flag.ToString();
                responseString += "\n" + resp_pb.backend_version.ToString();

                resp_list_pb = Serializer.DeserializeWithLengthPrefix<Response_CreateSession_PB>(streamResponse, PrefixStyle.Base128, 0);
                if (resp_pb.success_flag) responseString += "\n" + resp_list_pb.session.session_name;
                else
                {
                    responseString += "\n" + resp_pb.exception.message;
                }
            }
            catch (Exception e)
            {
                responseString = e.Message.ToString();
                System.Diagnostics.Debug.WriteLine("EXCEPTION string\n" + e.Data + "\n -- \n" + e.StackTrace.ToString());
            }

            System.Diagnostics.Debug.WriteLine("RESP string\n" + responseString);

            // Close the stream object
            streamResponse.Close();

            // Release the HttpWebResponse
            response.Close();

            Dispatcher.BeginInvoke(() =>
            {
                //Update UI here
                TextBlock1.Text = responseString;

            });
            }
            catch (WebException e)
            {
            //Handle non success exception here
            HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;

            System.Diagnostics.Debug.WriteLine("responses suck");

            }
        }
 public CollabrifyEventArgs(CollabrifyResponse_PB response_pb, object specific_response_pb, CollabrifyRequestType_PB request_type)
 {
     type = request_type;
     specificResponsePB = specific_response_pb;
     response = response_pb;
 }
        // -------------------------------------------------------------------------
        private void GetResponseCallback(IAsyncResult asynchronousResult)
        {
            try
              {
            HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;
            HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);

            //to read server response
            Stream streamResponse = response.GetResponseStream();
            try
            {
              collabrify_resp_pb = Serializer.DeserializeWithLengthPrefix<CollabrifyResponse_PB>(streamResponse, PrefixStyle.Base128, 0);

              returned_secondary_pb = null;
              if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.ADD_EVENT_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_AddEvent_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.ADD_PARTICIPANT_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_AddParticipant_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.ADD_TO_BASE_FILE_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_AddToBaseFile_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.CREATE_OR_GET_USER)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_CreateOrGetUser_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.CREATE_SESSION_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_CreateSession_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.CREATE_SESSION_WITH_BASE_FILE_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_CreateSessionWithBaseFile_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.DELETE_ALL_SESSIONS_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_DeleteAllSessions_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.DELETE_OLD_SESSIONS_REQUEST)
              {
            // TODO: DELETE OLD SESSIONS??
            // returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_DeleteAllSessions_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.DELETE_SESSION_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_DeleteSession_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.DELETE_USER)
              {
            // TODO: DELETE USER??
            // returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_DeleteSession_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.END_SESSION_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_EndSession_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.GET_BASE_FILE_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_GetBaseFile_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.GET_CURRENT_ORDER_ID_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_GetCurrentOrderID_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.GET_EVENT_BATCH_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_GetEventBatch_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.GET_EVENT_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_GetEvent_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.GET_FROM_BASE_FILE_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_GetFromBaseFile_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.GET_LAST_EVENT_BY_PARTICIPANT_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_GetLastEventByParticipant_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.GET_NOTIFICATION_ID_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_GetNotificationID_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.GET_PARTICIPANT_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_GetParticipant_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.GET_SESSION_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_GetSession_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.LIST_ACCOUNTS_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_ListAccounts_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.LIST_SESSIONS_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_ListSessions_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.PREVENT_FURTHER_JOINS_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_PreventFurtherJoins_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.REMOVE_PARTICIPANT_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_RemoveParticipant_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.REQUEST_TYPE_NOT_SET)
              {
            // TODO
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.UPDATE_NOTIFICATION_ID_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_UpdateNotificationID_PB>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.UPDATE_USER)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_UpdateUser>(streamResponse, PrefixStyle.Base128, 0);
              }
              else if (collabrify_req_pb.request_type == CollabrifyRequestType_PB.WARMUP_REQUEST)
              {
            returned_secondary_pb = Serializer.DeserializeWithLengthPrefix<Response_Warmup_PB>(streamResponse, PrefixStyle.Base128, 0);
              }

              // invokes an event that is returned to the cliend object.
              CollabrifyEventArgs e = new CollabrifyEventArgs(collabrify_resp_pb, returned_secondary_pb, collabrify_req_pb.request_type);

              try
              {
            if (HttpRequestDone != null) HttpRequestDone.Invoke(e);
            else Debug.WriteLine("Changed event is null");
              } // try
              catch
              {
            Debug.WriteLine("OnChanged exception...");
              } // catch

            } // try
            catch (Exception e)
            {
              System.Diagnostics.Debug.WriteLine(LOG_TAG + " Error:\nMessage: " + e.Message.ToString() + "\ndata: " + e.Data.ToString() + "\n -- \n" + e.StackTrace.ToString());
            } // catch

            // Close the stream object
            streamResponse.Close();

            // Release the HttpWebResponse
            response.Close();

              } // try
              catch (WebException e)
              {
            System.Diagnostics.Debug.WriteLine(LOG_TAG + " Error:\nMessage: " + e.Message.ToString() + "\ndata: " + e.Data.ToString() + "\n -- \n" + e.StackTrace.ToString());
              } // catch
        }