protected void Page_Load(object sender, EventArgs e) { if (Application["RMKGuide"] == null) { Application["RMKGuide"] = new List <string>(); } List <string> RMKGuide = (List <string>)(Application["RMKGuide"]); Response.ContentType = "text/xml"; StreamReader reader = new StreamReader(Request.InputStream); String xmlData = reader.ReadToEnd(); RMKRequestData rqd = new RMKRequestData(); RMKResponseData rsd = new RMKResponseData(); try { rqd.parseRequest(xmlData); if (rqd.operationId.Length < 1) { rsd.operationId = Guid.NewGuid().ToString(); rsd.message = "Операция успешно сохранена"; } else { rsd.operationId = ""; } } catch (Exception e1) { rsd.status = false; rsd.operationId = ""; rsd.message = e1.Message; } Application["RMKGuide"] = RMKGuide; Response.Write(rsd.createResponse()); Response.End(); }
private RMKResponseData RunRequest(string bodyPost) { HttpWebRequest req = null; try { byte[] body = Encoding.GetEncoding("UTF-8").GetBytes(bodyPost); req = (HttpWebRequest)WebRequest.Create(_url); req.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0"; req.Timeout = 45 * 1000; req.Method = "POST"; req.ContentType = "text/xml"; req.ProtocolVersion = HttpVersion.Version11; req.ContentLength = 0; if (body != null) { req.ContentLength = body.Length; using (var writer = req.GetRequestStream()) { writer.Write(body, 0, body.Length); writer.Flush(); writer.Close(); } } using (var resp = (HttpWebResponse)req.GetResponse()) { StreamReader streamR = new StreamReader(resp.GetResponseStream(), Encoding.GetEncoding("UTF-8")); String content = streamR.ReadToEnd(); streamR.Close(); resp.Close(); RMKResponseData rd = new RMKResponseData(); if (content == null || content.Length < 1) { rd.status = false; rd.operationId = ""; rd.message = "Не получены данные от службы"; } else { rd.parseResponse(content); } return(rd); } } catch (WebException we) { throw new Exception(we.Status.ToString() + " " + we.Message); } catch (Exception e) { RMKResponseData rd = new RMKResponseData(); rd.status = false; rd.operationId = ""; rd.message = e.Message; return(rd); } finally { if (req != null) { req.Abort(); } req = null; } }
private RMKResponseData RunRequestService(string body) { RMKResponseData res = null; //string str = "<?xml version =\"1.0\" encoding =\"utf-16\"?><RmkResponse xmlns:xsi =\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd = \"http://www.w3.org/2001/XMLSchema\"><status>true</status><OperationID>1d51cf78-e64f-468a-a2ea-f507f43cbbc3</OperationID></RmkResponse>"; //res = new RMKResponseData(); //WebLog.LogClass.WriteToLog("Ответ сервиса: {0}", str); //if (String.IsNullOrEmpty(str)) //{ // res.status = false; // res.operationId = ""; // res.message = "Не получены данные от службы"; //} //else //{ // res.parseResponse(str); //} //return res; BasicHttpBinding binding = new BasicHttpBinding(); binding.Name = "BasicHttpBinding_CaPService"; binding.CloseTimeout = TimeSpan.FromMinutes(1); binding.OpenTimeout = TimeSpan.FromMinutes(1); binding.ReceiveTimeout = TimeSpan.FromMinutes(10); binding.SendTimeout = TimeSpan.FromMinutes(1); binding.AllowCookies = false; binding.BypassProxyOnLocal = false; binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard; binding.MaxBufferSize = 65536; binding.MaxBufferPoolSize = 524288; binding.MessageEncoding = WSMessageEncoding.Text; binding.TextEncoding = System.Text.Encoding.UTF8; binding.TransferMode = TransferMode.Buffered; binding.UseDefaultWebProxy = true; binding.ReaderQuotas.MaxDepth = 32; binding.ReaderQuotas.MaxStringContentLength = 8192; binding.ReaderQuotas.MaxArrayLength = 16384; binding.ReaderQuotas.MaxBytesPerRead = 4096; binding.ReaderQuotas.MaxNameTableCharCount = 16384; LogData = "RMK request:\n"; if (String.IsNullOrEmpty(_url)) { if (!isService) { WebLog.LogClass.WriteToLog(body); } else { LogData += body; } RMKResponseData r = new RMKResponseData(); r.status = true; r.message = "debug result: ok"; r.operationId = Guid.NewGuid().ToString(); LogData += "\nRMK emulation response:\n"; LogData += r.createResponse(); return(r); } Uri baseAddress = new Uri(_url); if (!isService) { WebLog.LogClass.WriteToLog(body); } else { LogData += body; } using (ChannelFactory <RmkTwoCaPService.IBasicHttpBinding_CaPService> ServiceProxy = new ChannelFactory <RmkTwoCaPService.IBasicHttpBinding_CaPService>(binding, new EndpointAddress(baseAddress))) { ServiceProxy.Open(); RmkTwoCaPService.IBasicHttpBinding_CaPService client = ServiceProxy.CreateChannel(); string stream = client.CreateCaPOperation(body); res = new RMKResponseData(); LogData += "\nRMK response:\n"; if (!isService) { WebLog.LogClass.WriteToLog("Ответ сервиса: {0}", stream); } else { LogData += stream; } if (String.IsNullOrEmpty(stream)) { res.status = false; res.operationId = ""; res.message = "Не получены данные от службы"; } else { res.parseResponse(stream); } return(res); } }