public static void TestRequest() { string enterStr = ""; try { while (!enterStr.Equals("exit")) { Console.WriteLine("Enter OrderNo:"); enterStr = Console.ReadLine(); try { RestRequest restRequest = new RestRequest(ConfigurationManager.AppSettings["RequestUrl"], enterStr); restRequest.Execute(); Console.WriteLine("Success!"); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } //RestRequest restRequest = new RestRequest("http://127.0.0.1:21111/Messages/Create301", "68544065718738"); //RestRequest restRequest = new RestRequest("http://127.0.0.1:21111/Messages/Create301", "68867519419577"); //RestRequest restRequest = new RestRequest("http://10.0.0.195:21111/Messages/Get", "", "GET"); //RestRequest restRequest = new RestRequest("http://127.0.0.1:21111/Messages/Get", "", "GET"); //RestRequest restRequest = new RestRequest("http://10.0.0.195:21111/Messages/GetByGuid", "E098ABBE-BE54-4493-8BCB-5BF0CD4AF01F"); //var a = restRequest.Execute(); } catch (Exception ex) { } }
private void btnCreate501_Click(object sender, EventArgs e) { string url = null; RestRequest rest = null; try { if (CheckValue(501)) { url = string.Format("{0}/Messages/Create501/{1}", a_requestObj.RequestUrl, a_requestObj.OrderNoFake); rest = new RestRequest(url); rest.Execute(); MessageBox.Show("Success!"); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public string Execute(ExecuteAction action, string param = "") { RestRequest restRequest = null; switch (action) { case ExecuteAction.Get: case ExecuteAction.GetCache: restRequest = new RestRequest(this.a_restUrl + action.ToString(), param, "GET"); break; case ExecuteAction.AwakeThread: case ExecuteAction.Clear: case ExecuteAction.GetByGuid: case ExecuteAction.GetByFilter: restRequest = new RestRequest(this.a_restUrl + action.ToString(), param, "POST"); break; default: break; } return restRequest.Execute(); }
public bool CreateMessage503R(string logisticsNo) { bool success = true; LogisticsStatus logisticsStatus = null; MessageSql mssql = null; MessageService msService = null; XElement xele = null; XNamespace ns = null; try { mssql = new MessageSql(); logisticsStatus = new LogisticsStatus(); mssql.QueryData503ByLogisticsNo(logisticsNo, ref logisticsStatus); if (logisticsStatus.guid != new Guid()) { string url = GetRequestHostByCode(logisticsStatus.logisticsCode); RestRequest restRequest = new RestRequest(string.Format("{0}:{1}/Logistics/Create503", url, ConfigurationInfo.RestPort), Utilities.JsonSerialize(logisticsStatus)); success = Convert.ToBoolean(restRequest.Execute()); } else { success = false; } if (success) { mssql.UpdateSchedule503(null, logisticsNo); ns = "http://www.chinaport.gov.cn/ceb"; xele = new XElement(ns + "CEB503Message"); xele.SetAttributeValue(XNamespace.Xmlns + "ceb", ns); xele = logisticsStatus.ToXElememt(xele, ns); string destPath = FileUtilities.GetNewFolderName(true, ConfigurationInfo.PathBackUp, "503") + "\\" + FileUtilities.GetNewFileName(logisticsNo, "Create", "R") + ".xml"; xele.Save(destPath); msService = new MessageService(); msService.DealMessage503(false, true, logisticsStatus.guid.ToString(), logisticsNo, destPath, "R"); } else { success = false; Logs.Info("CreateMessage503R Response Error! Date:" + Utilities.JsonSerialize(logisticsStatus)); } } catch (Exception ex) { success = false; Logs.Error("CreateMessage503R Exception: " + ex.ToString()); } return success; }
public bool CreateMessage501(string orderNoFake) { bool success = true; LogisticsHead logisticsHead = null; MessageSql mssql = null; MessageService msService = null; XElement xele = null; XNamespace ns = null; try { mssql = new MessageSql(); logisticsHead = new LogisticsHead(); mssql.QueryData501(orderNoFake, ref logisticsHead); if (logisticsHead.guid != new Guid()) { string url = GetRequestHostByCode(logisticsHead.logisticsCode); RestRequest restRequest = new RestRequest(string.Format("{0}:{1}/Logistics/Create501", url, ConfigurationInfo.RestPort), Utilities.JsonSerialize(logisticsHead)); success = Convert.ToBoolean(restRequest.Execute()); } else { success = false; } if (success) { mssql.UpdateSchedule501(orderNoFake, logisticsHead.billNo, logisticsHead.weight.ToString(), logisticsHead.freight.ToString()); ns = "http://www.chinaport.gov.cn/ceb"; xele = new XElement(ns + "CEB501Message"); xele.SetAttributeValue(XNamespace.Xmlns + "ceb", ns); xele = logisticsHead.ToXElememt(xele, ns); string destPath = FileUtilities.GetNewFolderName(true, ConfigurationInfo.PathBackUp, "501") + "\\" + FileUtilities.GetNewFileName(orderNoFake, "Create") + ".xml"; xele.Save(destPath); msService = new MessageService(); msService.DealMessage501(false, true, logisticsHead.guid.ToString(), orderNoFake, logisticsHead.logisticsNo, destPath); } else { Logs.Info("Create501Message Response Error! Date:" + Utilities.JsonSerialize(logisticsHead)); } } catch (Exception ex) { success = false; Logs.Error("Create501Message Exception: " + ex.ToString()); } finally { if (!success) { MessageCache.DeleteMessageCache("503R" + logisticsHead.logisticsNo); MessageCache.DeleteMessageCache("601" + logisticsHead.logisticsNo); } } return success; }
static void Main(string[] args) { try { MessageFilter filter = new MessageFilter() { Guid = new Guid("B88ED620-078C-4E0E-9182-E4D4F008BD57") }; RestRequest restRequest = new RestRequest("http://61.189.20.116:21111/Messages/DeleteByGuid", Utilities.JsonSerialize(filter)); var a = restRequest.Execute(); } catch (Exception ex) { } }