using System;
using System.Xml;
using System.IO;
using System.Net;
using System.Configuration;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Xml.Schema;
using System.Xml.XPath;
using System.Net.Mail;
using CDMARSS;
using CDMARSS.BLL;
using CDMARSS.BLL.MessageHeader;
using CDMARSS.BLL.OrderResponse;
using CDMARSS.DAL;
using CDMARSS.DAL.Logs;
public partial class Receive : System.Web.UI.Page
{
private XmlDocument objInputXML;
private int RETURN_CODE = 0;
private string RETURN_ERROR_TEXT = "";
private string FormData = null;
protected void Page_Load(object sender, EventArgs e)
{
log4net.ILog Log = log4net.LogManager.GetLogger("Receive.aspx");
// Getting ip of visitor
string ip = Request.ServerVariables["REMOTE_ADDR"];
// Getting the page which called the script
string page = Request.ServerVariables["HTTP_REFERER"];
// Getting Browser Name of Visitor
string browser = "N/A";
if (Request.ServerVariables["HTTP_USER_AGENT"].Contains("MSIE"))
browser = "Internet Explorer";
if (Request.ServerVariables["HTTP_USER_AGENT"].Contains("FireFox"))
browser = "Fire Fox";
if (Request.ServerVariables["HTTP_USER_AGENT"].Contains("Opera"))
browser = "Opera";
Log.Info("FormData= " + FormData);
Log.Info("Remote_Address = " + ip);
Log.Info("Http_Referer = " + page);
Log.Info("Browser = " + browser);
string info = "";
// Get Input Stream and store it in string
info = info + "CDMA Async Response. Time of arrival: ";
info = info + DateTime.Now.ToString();
info = info + " FormData= " + FormData + ", Remote_Address = " + ip + ", Http_Referer = " + page + ", Browser = " + browser;
//Send email
SmtpClient client = new SmtpClient(ConfigurationManager.AppSettings["MailServer"].ToString());
MailMessage objMM = new MailMessage(ConfigurationManager.AppSettings["EmailProcessFROM"].ToString(), ConfigurationManager.AppSettings["EmailProcessTO"].ToString());
objMM.Subject = "Response Coming In.";
objMM.Body = info;
client.Send(objMM);
byte[] B = new byte[Request.InputStream.Length + 1];
Request.InputStream.Read(B, 0, B.Length);
FormData = System.Text.ASCIIEncoding.ASCII.GetString(B);
// Check Request Server Variables
if (Request.ServerVariables["REQUEST_METHOD"].ToUpper() != "POST")
RETURN_CODE = (int)ResponseCodes.InvalidRequestMethod;
// if not invalid request then process post data
if (RETURN_CODE != (int)ResponseCodes.InvalidRequestMethod)
ProcessPostData(FormData);
}
private void ProcessPostData(string FormData)
{
objInputXML = new XmlDocument();
OrderResponse OrdResponse = new OrderResponse();
MessageHeader MsgHeader = new MessageHeader();
//load up an XML document from the post data
try
{
objInputXML.LoadXml(System.Convert.ToString(FormData));
//
//Collect the header data
//
XmlNodeList objNode = default(XmlNodeList);
objNode = objInputXML.GetElementsByTagName("messageHeader");
if (objNode.Item(0).ChildNodes.Count != Globals.REQUIRED_NUM_CHLD_HEADER)
{
RETURN_CODE = (int)ResponseCodes.InvalidHeaderChildren;
RETURN_ERROR_TEXT += "The number of child elements of the header was " + objNode.Item(0).ChildNodes.Count.ToString() + " a should have been " + Globals.REQUIRED_NUM_CHLD_HEADER.ToString() + "<br>";
}
else
{
MsgHeader.VersionNumber = objNode[0].ChildNodes[0].InnerText;
MsgHeader.VendorID = objNode[0].ChildNodes[1].InnerText;
MsgHeader.ChannelID = objNode[0].ChildNodes[2].InnerText;
MsgHeader.ChannelType = objNode[0].ChildNodes[3].InnerText;
MsgHeader.RequestType = objNode[0].ChildNodes[4].InnerText;
MsgHeader.OrderType = objNode[0].ChildNodes[5].InnerText;
MsgHeader.ReferenceNumber = objNode[0].ChildNodes[6].InnerText;
MsgHeader.ReturnURL = objNode[0].ChildNodes[7].InnerText;
}
//
//Collect the reponse
//
objNode = objInputXML.GetElementsByTagName("orderResponse");
if (objNode.Item(0).ChildNodes.Count != Globals.REQUIRED_NUM_CHLD_RESPONSE)
{
RETURN_CODE = (int)ResponseCodes.InvalidOrderResponseChildren;
RETURN_ERROR_TEXT += "The number of child elements of the response was " + objNode.Item(0).ChildNodes.Count.ToString() + " a should have been " + Globals.REQUIRED_NUM_CHLD_RESPONSE.ToString() + "<br>";
}
else
{
OrdResponse.MDN = Convert.ToInt32(objNode[0].ChildNodes[0].InnerText);
OrdResponse.MIN = Convert.ToInt32(objNode[0].ChildNodes[1].InnerText);
OrdResponse.StatusCode = objNode[0].ChildNodes[2].InnerText;
OrdResponse.ErrorCode = objNode[0].ChildNodes[3].InnerText;
if (object.ReferenceEquals(objNode[0].ChildNodes[3].InnerText, DBNull.Value) ||
objNode[0].ChildNodes[3].InnerText == " ")
{
OrdResponse.ErrorCode = "None";
}
OrdResponse.ErrorDescription = objNode[0].ChildNodes[4].InnerText;
}
//Done with objNode
objNode = null;
objInputXML = null;
RETURN_CODE = DBCRUID.InsertIntoDBCheckResponse(MsgHeader, OrdResponse, Request.ServerVariables["REMOTE_ADDR"].ToString());
}
catch (Exception ex)
{
RETURN_CODE = (int)ResponseCodes.InvalidXMLData;
RETURN_ERROR_TEXT += ex.Message + "<br>";
}
Response.Clear();
Response.ContentType = "text/html";
//send HTML to the browser
Response.Write(RETURN_CODE.ToString() + "<br>" + RETURN_ERROR_TEXT);
}
}
http://odetocode.com/Blogs/scott/archive/2006/02/16/2914.aspx