/// <summary> /// This method creates a Session for an outgoing call or message. /// </summary> private void CreateSession() { try { CreateSessionClass createSessionData = new CreateSessionClass(); createSessionData.numberToDial = txtNumberToDial.Value; if (!string.IsNullOrEmpty(scriptType.Value)) { createSessionData.feature = scriptType.Value.ToString(); } else { createSessionData.feature = string.Empty; } createSessionData.messageToPlay = txtMessageToPlay.Value.ToString(); createSessionData.featurenumber = txtNumber.Value.ToString(); System.Web.Script.Serialization.JavaScriptSerializer oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer(); string requestParams = oSerializer.Serialize(createSessionData); string createSessionResponse; HttpWebRequest createSessionRequestObject = (HttpWebRequest)System.Net.WebRequest.Create(string.Empty + this.endPoint + "/rest/1/Sessions"); createSessionRequestObject.Headers.Add("Authorization", "Bearer " + this.accessToken); createSessionRequestObject.Method = "POST"; createSessionRequestObject.ContentType = "application/json"; createSessionRequestObject.Accept = "application/json"; UTF8Encoding encoding = new UTF8Encoding(); byte[] postBytes = encoding.GetBytes(requestParams); createSessionRequestObject.ContentLength = postBytes.Length; Stream postStream = createSessionRequestObject.GetRequestStream(); postStream.Write(postBytes, 0, postBytes.Length); postStream.Close(); HttpWebResponse createSessionResponseObject = (HttpWebResponse)createSessionRequestObject.GetResponse(); using (StreamReader createSessionResponseStream = new StreamReader(createSessionResponseObject.GetResponseStream())) { createSessionResponse = createSessionResponseStream.ReadToEnd(); if (!string.IsNullOrEmpty(createSessionResponse)) { JavaScriptSerializer deserializeJsonObject = new JavaScriptSerializer(); CreateSessionResponse deserializedJsonObj = (CreateSessionResponse)deserializeJsonObject.Deserialize(createSessionResponse, typeof(CreateSessionResponse)); if (null != deserializedJsonObj) { sessionIdOfCreateSessionResponse = deserializedJsonObj.id.ToString(); Session["CsharpRestfulsessionId"] = sessionIdOfCreateSessionResponse; successOfCreateSessionResponse = deserializedJsonObj.success.ToString(); } else { createSessionErrorResponse = "Got response but not able to deserialize json" + createSessionResponse; } } else { createSessionErrorResponse = "Success response but with empty ad"; } createSessionResponseStream.Close(); } } catch (WebException we) { string errorResponse = string.Empty; try { using (StreamReader sr2 = new StreamReader(we.Response.GetResponseStream())) { errorResponse = sr2.ReadToEnd(); sr2.Close(); } } catch { errorResponse = "Unable to get response"; } createSessionErrorResponse = errorResponse + Environment.NewLine + we.ToString(); } catch (Exception ex) { createSessionErrorResponse = ex.ToString(); } }
/// <summary> /// This method creates a Session for an outgoing call or message. /// </summary> private void CreateSession() { try { CreateSessionClass createSessionData = new CreateSessionClass(); createSessionData.numberToDial = txtNumberToDial.Text.ToString(); if (lstTemplate.SelectedValue != "") createSessionData.feature = lstTemplate.SelectedValue.ToString(); else createSessionData.feature = string.Empty; createSessionData.messageToPlay = txtMessageToPlay.Text.ToString(); createSessionData.featurenumber = txtNumberForFeature.Text.ToString(); System.Web.Script.Serialization.JavaScriptSerializer oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer(); string requestParams = oSerializer.Serialize(createSessionData); string createSessionResponse; HttpWebRequest createSessionRequestObject = (HttpWebRequest)System.Net.WebRequest.Create(string.Empty + this.endPoint + "/rest/1/Sessions"); createSessionRequestObject.Headers.Add("Authorization", "Bearer " + this.accessToken); createSessionRequestObject.Method = "POST"; createSessionRequestObject.ContentType = "application/json"; createSessionRequestObject.Accept = "application/json"; UTF8Encoding encoding = new UTF8Encoding(); byte[] postBytes = encoding.GetBytes(requestParams); createSessionRequestObject.ContentLength = postBytes.Length; Stream postStream = createSessionRequestObject.GetRequestStream(); postStream.Write(postBytes, 0, postBytes.Length); postStream.Close(); HttpWebResponse createSessionResponseObject = (HttpWebResponse)createSessionRequestObject.GetResponse(); using (StreamReader createSessionResponseStream = new StreamReader(createSessionResponseObject.GetResponseStream())) { createSessionResponse = createSessionResponseStream.ReadToEnd(); if (!string.IsNullOrEmpty(createSessionResponse)) { JavaScriptSerializer deserializeJsonObject = new JavaScriptSerializer(); CreateSessionResponse deserializedJsonObj = (CreateSessionResponse)deserializeJsonObject.Deserialize(createSessionResponse, typeof(CreateSessionResponse)); if (null != deserializedJsonObj) { lblSessionId.Text = deserializedJsonObj.id.ToString(); NameValueCollection displayParam = new NameValueCollection(); displayParam.Add("id", deserializedJsonObj.id); displayParam.Add("success", deserializedJsonObj.success.ToString()); this.DrawPanelForSuccess(pnlCreateSession, displayParam, string.Empty); } else { this.DrawPanelForFailure(pnlCreateSession, "Got response but not able to deserialize json" + createSessionResponse); } } else { this.DrawPanelForFailure(pnlCreateSession, "Success response but with empty ad"); } createSessionResponseStream.Close(); } } catch (WebException we) { string errorResponse = string.Empty; try { using (StreamReader sr2 = new StreamReader(we.Response.GetResponseStream())) { errorResponse = sr2.ReadToEnd(); sr2.Close(); } } catch { errorResponse = "Unable to get response"; } this.DrawPanelForFailure(pnlCreateSession, errorResponse + Environment.NewLine + we.ToString()); } catch (Exception ex) { this.DrawPanelForFailure(pnlCreateSession, ex.ToString()); } }
/// <summary> /// This method creates a Session for an outgoing call or message. /// </summary> private void CreateSession() { try { CreateSessionClass createSessionData = new CreateSessionClass(); createSessionData.numberToDial = txtNumberToDial.Text.ToString(); if (lstTemplate.SelectedValue != "") { createSessionData.feature = lstTemplate.SelectedValue.ToString(); } else { createSessionData.feature = string.Empty; } createSessionData.messageToPlay = txtMessageToPlay.Text.ToString(); createSessionData.featurenumber = txtNumberForFeature.Text.ToString(); System.Web.Script.Serialization.JavaScriptSerializer oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer(); string requestParams = oSerializer.Serialize(createSessionData); string createSessionResponse; HttpWebRequest createSessionRequestObject = (HttpWebRequest)System.Net.WebRequest.Create(string.Empty + this.endPoint + "/rest/1/Sessions"); createSessionRequestObject.Headers.Add("Authorization", "Bearer " + this.accessToken); createSessionRequestObject.Method = "POST"; createSessionRequestObject.ContentType = "application/json"; createSessionRequestObject.Accept = "application/json"; UTF8Encoding encoding = new UTF8Encoding(); byte[] postBytes = encoding.GetBytes(requestParams); createSessionRequestObject.ContentLength = postBytes.Length; Stream postStream = createSessionRequestObject.GetRequestStream(); postStream.Write(postBytes, 0, postBytes.Length); postStream.Close(); HttpWebResponse createSessionResponseObject = (HttpWebResponse)createSessionRequestObject.GetResponse(); using (StreamReader createSessionResponseStream = new StreamReader(createSessionResponseObject.GetResponseStream())) { createSessionResponse = createSessionResponseStream.ReadToEnd(); if (!string.IsNullOrEmpty(createSessionResponse)) { JavaScriptSerializer deserializeJsonObject = new JavaScriptSerializer(); CreateSessionResponse deserializedJsonObj = (CreateSessionResponse)deserializeJsonObject.Deserialize(createSessionResponse, typeof(CreateSessionResponse)); if (null != deserializedJsonObj) { lblSessionId.Text = deserializedJsonObj.id.ToString(); NameValueCollection displayParam = new NameValueCollection(); displayParam.Add("id", deserializedJsonObj.id); displayParam.Add("success", deserializedJsonObj.success.ToString()); this.DrawPanelForSuccess(pnlCreateSession, displayParam, string.Empty); } else { this.DrawPanelForFailure(pnlCreateSession, "Got response but not able to deserialize json" + createSessionResponse); } } else { this.DrawPanelForFailure(pnlCreateSession, "Success response but with empty ad"); } createSessionResponseStream.Close(); } } catch (WebException we) { string errorResponse = string.Empty; try { using (StreamReader sr2 = new StreamReader(we.Response.GetResponseStream())) { errorResponse = sr2.ReadToEnd(); sr2.Close(); } } catch { errorResponse = "Unable to get response"; } this.DrawPanelForFailure(pnlCreateSession, errorResponse + Environment.NewLine + we.ToString()); } catch (Exception ex) { this.DrawPanelForFailure(pnlCreateSession, ex.ToString()); } }
/// <summary> /// This method creates a Session for an outgoing call or message. /// </summary> private void CreateSession() { try { CreateSessionClass createSessionData = new CreateSessionClass(); createSessionData.numberToDial = txtNumberToDial.Value; if (!string.IsNullOrEmpty(scriptType.Value)) createSessionData.feature = scriptType.Value.ToString(); else createSessionData.feature = string.Empty; createSessionData.messageToPlay = txtMessageToPlay.Value.ToString(); createSessionData.featurenumber = txtNumber.Value.ToString(); System.Web.Script.Serialization.JavaScriptSerializer oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer(); string requestParams = oSerializer.Serialize(createSessionData); string createSessionResponse; HttpWebRequest createSessionRequestObject = (HttpWebRequest)System.Net.WebRequest.Create(string.Empty + this.endPoint + "/rest/1/Sessions"); createSessionRequestObject.Headers.Add("Authorization", "Bearer " + this.accessToken); createSessionRequestObject.Method = "POST"; createSessionRequestObject.ContentType = "application/json"; createSessionRequestObject.Accept = "application/json"; UTF8Encoding encoding = new UTF8Encoding(); byte[] postBytes = encoding.GetBytes(requestParams); createSessionRequestObject.ContentLength = postBytes.Length; Stream postStream = createSessionRequestObject.GetRequestStream(); postStream.Write(postBytes, 0, postBytes.Length); postStream.Close(); HttpWebResponse createSessionResponseObject = (HttpWebResponse)createSessionRequestObject.GetResponse(); using (StreamReader createSessionResponseStream = new StreamReader(createSessionResponseObject.GetResponseStream())) { createSessionResponse = createSessionResponseStream.ReadToEnd(); if (!string.IsNullOrEmpty(createSessionResponse)) { JavaScriptSerializer deserializeJsonObject = new JavaScriptSerializer(); CreateSessionResponse deserializedJsonObj = (CreateSessionResponse)deserializeJsonObject.Deserialize(createSessionResponse, typeof(CreateSessionResponse)); if (null != deserializedJsonObj) { sessionIdOfCreateSessionResponse = deserializedJsonObj.id.ToString(); Session["CsharpRestfulsessionId"] = sessionIdOfCreateSessionResponse; successOfCreateSessionResponse = deserializedJsonObj.success.ToString(); } else { createSessionErrorResponse = "Got response but not able to deserialize json" + createSessionResponse; } } else { createSessionErrorResponse = "Success response but with empty ad"; } createSessionResponseStream.Close(); } } catch (WebException we) { string errorResponse = string.Empty; try { using (StreamReader sr2 = new StreamReader(we.Response.GetResponseStream())) { errorResponse = sr2.ReadToEnd(); sr2.Close(); } } catch { errorResponse = "Unable to get response"; } createSessionErrorResponse = errorResponse + Environment.NewLine + we.ToString(); } catch (Exception ex) { createSessionErrorResponse = ex.ToString(); } }