mathieu_cupryk
asked on
AutoEventWireup="false"
what does this mean exactly.
If I am posting to this page data. What does this mean?
If I am posting to this page data. What does this mean?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
so if I want to post a web response to a page what do i do?
Say the person hits the page. how should I set this up.
Say the person hits the page. how should I set this up.
I'm sorry mathieu - you'll have to elaborate on what you mean by "post a web response to a page."
Are you familiar with asp.net (I just realized you posted this question in the C# section)?
Are you familiar with asp.net (I just realized you posted this question in the C# section)?
ASKER
I have a webpage called receive.aspx that is being called and a response of a web service needs to be passed.
U could say it is like a listener.
The question is if I am calling a page i need to somehow pass the respone through the page.
The value of the formdata should contain the web response. I need to see if the the response is hitting the page. How Shoud I setup my ui.
<%@ Page Language="C#" AutoEventWireup="false" Debug="true" Trace="true" CodeFile="Receive.aspx.cs" Inherits="Receive" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
U could say it is like a listener.
The question is if I am calling a page i need to somehow pass the respone through the page.
The value of the formdata should contain the web response. I need to see if the the response is hitting the page. How Shoud I setup my ui.
<%@ Page Language="C#" AutoEventWireup="false" Debug="true" Trace="true" CodeFile="Receive.aspx.cs"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
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);
}
}
I'm starting to follow you matheiu. You're either saying:
A) that you need send a response back to the client that originally made a POST to your recieve.aspx
or
B)that you need to send data to a DIFFERENT web page or service as part work that recieve.aspx is doing.
if your question is A) above, then the answer is simple - Just use Response as you already are to display RETURN_CODE and RETURN_ERROR_TEXT. The response doesn't have to be HTML. It can be anything - XML for example or even binary data (Response.BinaryWrite).
If your question is B) you'll have to make an HTTP request directly from your code with the HttpWebRequest class. This is a good example:
http://www.codeproject.com/KB/webservices/HttpWebRequest_Response.aspx
B
A) that you need send a response back to the client that originally made a POST to your recieve.aspx
or
B)that you need to send data to a DIFFERENT web page or service as part work that recieve.aspx is doing.
if your question is A) above, then the answer is simple - Just use Response as you already are to display RETURN_CODE and RETURN_ERROR_TEXT. The response doesn't have to be HTML. It can be anything - XML for example or even binary data (Response.BinaryWrite).
If your question is B) you'll have to make an HTTP request directly from your code with the HttpWebRequest class. This is a good example:
http://www.codeproject.com/KB/webservices/HttpWebRequest_Response.aspx
B
ASKER
i just need to setup the aspx page. To pass the input stream or should I say xml response.
http://odetocode.com/Blogs/scott/archive/2006/02/16/2914.aspx