using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Net;
using System.IO;
using System.Xml;

namespace Contact
{
	/// <summary>
	/// Summary description for servicerelay.
	/// </summary>
	public class servicerelay : System.Web.UI.Page
	{
		private void Page_Load(object sender, System.EventArgs e)
		{
			Response.Clear(); 
			WSCalc.CO2calc WS = new Contact.WSCalc.CO2calc();


//			string ClientCode = Request.QueryString["clientcode"];
//			string Code1 = Request.QueryString["code1"];
//			string Code2 = Request.QueryString["code2"];
//
//			DataSet ds = WS.Calculate(ClientCode,Code1,Code2);
//			
//			System.IO.MemoryStream streamResponse = new MemoryStream();
//
//			Response.Write(ds.GetXmlSchema());
//Response.Write(ds.GetXml());

			string QueryString = Request.RawUrl;





			int a = QueryString.LastIndexOf(".aspx/")+6;
			int b = QueryString.Length;
			QueryString = QueryString.Substring(a,b - a);

			//QueryString = "Calculate?clientcode=CATEST&code1=YYZ&code2=LHR";
			string url = @"http://calc.co2.org/co2calc.asmx/" + QueryString;
			// Create a new 'HttpWebRequest' object to the mentioned URL.
			HttpWebRequest myHttpWebRequest=(HttpWebRequest)HttpWebRequest.Create(url);
			// Assign the response object of 'HttpWebRequest' to a 'HttpWebResponse' variable.
			HttpWebResponse myHttpWebResponse=(HttpWebResponse)myHttpWebRequest.GetResponse();
			// Display the contents of the page to the console.
				
			Stream streamResponse=myHttpWebResponse.GetResponseStream();
			StreamReader streamRead = new StreamReader( streamResponse );
			Char[] readBuff = new Char[256];
			int count = streamRead.Read( readBuff, 0, 256 );
			   
			while (count > 0) 
			{
					String outputData = new String(readBuff, 0, count);
						Response.Write(outputData);
						count = streamRead.Read(readBuff, 0, 256);
					}
			 //Release the response object resources.
					streamRead.Close();
			//streamResponse.Write(Response.OutputStream)

		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.Load += new System.EventHandler(this.Page_Load);
		}
		#endregion
	}
}
