public static void GetMessageThreads() { string serviceUrl = Program.ROOT_URL + string.Format("InboxService.svc/messages/threads?startPage={0}&numberOfRecords={1}", 1, 25); var myRequest = (HttpWebRequest)WebRequest.Create(serviceUrl); myRequest.Method = "GET"; myRequest.ContentType = "application/xml"; myRequest.Headers.Add(DataLoadHelper.GetApIKeyToken()); myRequest.Headers.Add(string.Format("Rest-Impersonate-User:{0}", 4)); //post the request and get the response details using (var response = myRequest.GetResponse()) { if (response.ContentLength > 0) { using (var reader = new StreamReader(response.GetResponseStream())) { var messageThreads = DataLoadHelper.GetNodeValue(reader, "ResponseData"); //Assert.AreEqual(true, Convert.ToBoolean(DataLoadHelper.GetNodeValue(reader, "IsActive"))); Console.WriteLine("Method successfully called."); } } else { Console.WriteLine("Method called but result is not accurate."); } } }
public static void GetUnReadMessageCount() { string serviceUrl = Program.ROOT_URL + "InboxService.svc/messages/unread"; var myRequest = (HttpWebRequest)WebRequest.Create(serviceUrl); myRequest.Method = "GET"; myRequest.ContentType = "application/xml"; myRequest.Headers.Add(DataLoadHelper.GetApIKeyToken()); //post the request and get the response details using (var response = myRequest.GetResponse()) { if (response.ContentLength > 0) { using (var reader = new StreamReader(response.GetResponseStream())) { int count = Convert.ToInt32(DataLoadHelper.GetNodeValue(reader, "ResponseData")); if (count > -1) { Console.WriteLine("Method successfully called."); } else { { Console.WriteLine("Method called but result is not accurate."); } } } } else { Console.WriteLine("Method called but result is not accurate."); } } }
public static void GetMesesageThread() { string xmlPath = "TestData/MessageData.xml"; string threadID = DataLoadHelper.GetNodeValue(DataLoadHelper.GetXmlDocument(xmlPath), "ThreadID"); string serviceUrl = Program.ROOT_URL + string.Format("InboxService.svc/messages/thread/{0}", threadID); var myRequest = (HttpWebRequest)WebRequest.Create(serviceUrl); myRequest.Method = "GET"; myRequest.ContentType = "application/xml"; myRequest.Headers.Add(DataLoadHelper.GetApIKeyToken()); //post the request and get the response details using (var response = myRequest.GetResponse()) { if (response.ContentLength > 0) { using (var reader = new StreamReader(response.GetResponseStream())) { if (threadID == DataLoadHelper.GetNodeValue(reader, "ThreadID")) { Console.WriteLine("Method successfully called."); } else { Console.WriteLine("Method called but result is not accurate."); } } } else { Console.WriteLine("Method called but result is not accurate."); } } }
public static void CreateMessage() { try { string xmlPath = "TestData/MessageData.xml"; string apikey = DataLoadHelper.GetApIKeyToken(); string postData = DataLoadHelper.GetXmlAsString(xmlPath); //set the RESTful URL string serviceUrl = string.Format("{0}InboxService.svc/messages/message", Program.ROOT_URL); //set the content header type. Note: use "json" for JSON //create a new HttpRequest var myRequest = (HttpWebRequest)WebRequest.Create(serviceUrl); myRequest.Method = "POST"; myRequest.ContentType = "application/xml"; byte[] data = Encoding.UTF8.GetBytes(postData); myRequest.ContentLength = data.Length; //add the API key myRequest.Headers.Add(apikey); //add the data to be posted in the request stream var requestStream = myRequest.GetRequestStream(); requestStream.Write(data, 0, data.Length); requestStream.Close(); //post the request and get the response details using (var response = myRequest.GetResponse()) { if (response.ContentLength > 0) { using (var reader = new StreamReader(response.GetResponseStream())) { var result = DataLoadHelper.GetNodeValue(reader, "ResponseData"); if (!string.IsNullOrEmpty(result)) { if (Convert.ToInt32(result) > 0) { Console.WriteLine("Method successfully called."); } else { Console.WriteLine("Method called but result is not accurate."); } } else { Console.WriteLine("Failed"); } } } else { Console.WriteLine("Method called but result is not accurate."); } } } catch (Exception exception) { Console.WriteLine(string.Format("Failed because:{0}", exception.Message)); } }