Create a xml record

  • Thread starter Luis Esteban Valencia
  • Start date
L

Luis Esteban Valencia

Hello. I got this message

<ns0:Orden xmlns:ns0="http://localhost/CreditCheck">
<IdCliente>10</IdCliente>
- <Pedido>
<IdProducto>IdProducto_0</IdProducto>
<Cantidad>10.4</Cantidad>
<PrecioUnitario>10.4</PrecioUnitario>
</Pedido>
<Estado>Estado_0</Estado>
</ns0:Orden>

And I am trying to create the message with this code. but I dont know how
to do the record.


private void btnEnviar_Click(object sender, System.EventArgs e)

{

string requestLocation = "http://localhost/HwsMessages/BTSHTTPReceive.dll";

Status.Text = "";

XmlDocument xmlDocument = new XmlDocument();

xmlDocument.PreserveWhitespace = true;

XmlNode tempXmlNode = xmlDocument.CreateNode(XmlNodeType.Element, "Orden",
"http://localhost");

xmlDocument.AppendChild(tempXmlNode);


tempXmlNode = xmlDocument.CreateNode(XmlNodeType.Element, "IdCliente", "");

tempXmlNode.InnerText = txtidcliente.Text;

xmlDocument.DocumentElement.AppendChild(tempXmlNode);

tempXmlNode = xmlDocument.CreateNode(XmlNodeType.Element, "Timestamp", "");

DateTime now = DateTime.Now;

tempXmlNode.InnerText = now.ToString("s");

xmlDocument.DocumentElement.AppendChild(tempXmlNode);

tempXmlNode = xmlDocument.CreateNode(XmlNodeType.Element, "Notes", "");

tempXmlNode.InnerText = Notes.Text;

xmlDocument.DocumentElement.AppendChild(tempXmlNode);

try

{

HttpWebRequest request = (HttpWebRequest)
HttpWebRequest.Create(requestLocation);

request.Method = "POST";

ASCIIEncoding encoding = new ASCIIEncoding();

byte[] requestData = encoding.GetBytes(xmlDocument.OuterXml);

request.ContentType="application/x-www-form-urlencoded";

request.ContentLength = xmlDocument.OuterXml.Length;

Status.Text += "Submitting activity message";

Stream requestStream = request.GetRequestStream();

requestStream.Write(requestData,0,requestData.Length);

requestStream.Flush();

requestStream.Close();

HttpWebResponse response = (HttpWebResponse) request.GetResponse();

StreamReader responseData = new StreamReader( response.GetResponseStream());

Status.Text = System.Web.HttpUtility.HtmlEncode( responseData.ReadToEnd()) +
"<br>";

}

catch (WebException wex)

{

Status.Text = "Unable to complete web request. Web Exception error: " +
wex.Message;

}

}



Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top