Tuesday, July 7, 2009

HttpWebRequest & WebRequest in WebServices

protected void btnWebRequest_Click(object sender, EventArgs e)
{
//string xmlfile;
//xmlfile = Request.Params["xmlfile"];
//if (xmlfile == null)
// xmlfile = "uddi.xml";
//HttpSOAPRequest(xmlfile, null);
//string xmlfile = "uddi.xml";
string xmlfile = "myRequest.xml";

HttpSOAPRequest(xmlfile, null);

}


void HttpSOAPRequest(String xmlfile, string proxy)
{
XmlDocument doc = new XmlDocument();
doc.Load(@"D:\Applications\FridViewManipulation\" + xmlfile);
// HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://uddi.microsoft.com/inquire");
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://localhost:1709/FridViewManipulation/WebService.asmx");
if (proxy != null) req.Proxy = new WebProxy(proxy, true);
// if SOAPAction header is required, add it here...
//req.Headers.Add("SOAPAction", "\"\"");
req.Headers.Add("SOAPAction", "http://tempuri.org/Identify");
req.ContentType = "text/xml;charset=\"utf-8\"";
req.Accept = "text/xml";
req.Method = "POST";
Stream stm = req.GetRequestStream();
doc.Save(stm);
stm.Close();
WebResponse resp = req.GetResponse();
stm = resp.GetResponseStream();
StreamReader r = new StreamReader(stm);
// process SOAP return doc here. For now, we'll just send the XML out to the browser ...
// Response.Write(r.ReadToEnd());
dvResponse.InnerHtml = r.ReadToEnd();
}

myRequest.xml




Mayank