BizTalk Server General - Create a Record in .net

This is Interesting: Free IT Magazines  
Home > Archive > BizTalk Server General > July 2005 > Create a Record in .net





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Create a Record in .net
Luis Esteban Valencia

2005-07-28, 7:49 am

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




Scott Colestock

2005-07-28, 5:52 pm

Well, use AppendChild on the node associated with Pedido for the child
elements of Pedido.

Or consider using xsd.exe to create a class that can serialize this format
for you.

Scott Colestock
www.traceofthought.net


"Luis Esteban Valencia" <levalencia@avansoft.com> wrote in message
news:eS5AHT3kFHA.2152@TK2MSFTNGP14.phx.gbl...
> 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
>
>
>
>



Luis Esteban Valencia

2005-07-28, 5:52 pm

Something like this??



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);

XmlNode tempXmlNodePedido = xmlDocument.CreateNode(XmlNodeType.Element,
"Pedido");

tempXmlNodePedido = xmlDocument.CreateNode(XmlNodeType.Element, "Pedido",
"");

xmlDocument.DocumentElement.AppendChild(tempXmlNodePedido);

tempXmlNodePedido = xmlDocument.CreateNode(XmlNodeType.Element,
"idproducto", "");

tempXmlNodePedido.InnerText =txtproductid.Text;

tempXmlNodePedido.DocumentElement.AppendChild(tempXmlNode);

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

tempXmlNode.InnerText = txtqty.Text;

tempXmlNodePedido.DocumentElement.AppendChild(tempXmlNode);

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

tempXmlNode.InnerText = txtpreciounitario.Text;

tempXmlNodePedido.DocumentElement.AppendChild(tempXmlNode);

"Scott Colestock" <scolestock@community.nospam> escribió en el mensaje
news:eTauup4kFHA.3436@tk2msftngp13.phx.gbl...
> Well, use AppendChild on the node associated with Pedido for the child
> elements of Pedido.
>
> Or consider using xsd.exe to create a class that can serialize this format
> for you.
>
> Scott Colestock
> www.traceofthought.net
>
>
> "Luis Esteban Valencia" <levalencia@avansoft.com> wrote in message
> news:eS5AHT3kFHA.2152@TK2MSFTNGP14.phx.gbl...
how[vbcol=seagreen]
"Orden",[vbcol=seagreen]
responseData.ReadToEnd())[vbcol=seagreen]
>
>



Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com