chieftain1
Technical User
I’ve created several web forms in VS.NET in C# that do similar functions (allow users to insert data in text boxes, and check boxes, then submit an XML message via SOAP). This one is a bit different. I want users to submit data from an Excel Spreadsheet generated XML file, select items in a CheckBoxList and submit the form. The Excel generated XML file does not have a set number of lines but will have repeatable data that may appear between one and 60 times. My example below includes the repeatable data five times. An XSL file exists that displays the XML file on the Web form page from an XML Control. However, I’m unable to figure out the correct C# that sends the data from the displayed XML file (see ** in C# for my attempted code). I’m also not able to send the checked items in the CheckBoxList (see ***** in C# for my attempted code). If I do not check either box in the CheckBoxList, the page runs, but the imported XML data isn’t sent I receive a 500 error from the server. I included the bold TGML Type Face for easy viewing in the C# section below.
The following is my XML template:
<?xml version="1.0" encoding="utf-8" ?>
<soap:Envelope xmlns:xsi=" xmlns:xsd=" xmlns:soap=" <soap:Body>
<calTableUpdate xmlns=" <iccHeader>
<messageType xmlns=" <originator xmlns=" ">user</originator>
<originatorAddress xmlns=" <recipient xmlns=" <creationTimeString xmlns=" ">????</creationTimeString>
<messageId xmlns=" ">12345</messageId>
</iccHeader>
<calibrationFileList>
<transferDirection xmlns=" xyz.com ">Push</transferDirection>
<location xmlns=" <logicalName xmlns=" <physicalName xmlns=" <sizeInKiloBytes xmlns=" </calibrationFileList>
<disseminationList>IRS</disseminationList>
</calTableUpdate>
</soap:Body>
</soap:Envelope>
The following is my Excel Spreadsheet generated XML:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<?xml-stylesheet type="text/xsl" href="TC1B_Cal5.xls.xsl"?>
<!-- This XML file is generated by RustemSoft XML Converter Evaluation version -->
<table name="TC1B_Cal">
<TC1B_Cal>
<transferDirection>Push</transferDirection>
<location> <logicalName>12347.txt</logicalName>
<sizeInKiloBytes>20</sizeInKiloBytes>
</TC1B_Cal>
<TC1B_Cal>
<transferDirection>Push</transferDirection>
<location> <logicalName>12348.txt</logicalName>
<sizeInKiloBytes>14</sizeInKiloBytes>
</TC1B_Cal>
<TC1B_Cal>
<transferDirection>Push</transferDirection>
<location> <logicalName>12349.txt</logicalName>
<sizeInKiloBytes>11</sizeInKiloBytes>
</TC1B_Cal>
<TC1B_Cal>
<transferDirection>Push</transferDirection>
<location> <logicalName>12345.txt</logicalName>
<sizeInKiloBytes>8</sizeInKiloBytes>
</TC1B_Cal>
<TC1B_Cal>
<transferDirection>Push</transferDirection>
<location> <logicalName>12346.txt</logicalName>
<sizeInKiloBytes>17</sizeInKiloBytes>
</TC1B_Cal>
</table>
The following is my C# code for the Web form:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Net;
using System.Text;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Xml;
namespace Forms
{
/// <summary>
/// Summary description for Cal_Table_Update_Form.
/// </summary>
public class Cal_Table_Update : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox transferDirection;
protected System.Web.UI.WebControls.TextBox location;
protected System.Web.UI.WebControls.TextBox logicalName;
protected System.Web.UI.HtmlControls.HtmlForm Form1;
protected System.Web.UI.WebControls.TextBox sizeInKiloBytes;
protected System.Web.UI.WebControls.CheckBoxList disseminationList;
protected System.Web.UI.WebControls.Xml calibrationFileList;
protected System.Web.UI.WebControls.Button btnSubmit;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
#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.btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnSubmit_Click(object sender, System.EventArgs e)
{
// load an xml document from the basic soap package file
XmlDocument msg = ((Global)Context.ApplicationInstance).SoapSetup( "xmlCTU" );
// select the header node as a working element
XmlNode hdr = msg.GetElementsByTagName( "iccHeader" )[0];
// set variant data in the header node sub elements
hdr[ "originatorAddress", " ].InnerText = Context.Request.PhysicalPath;
hdr[ "creationTimeString", " " ].InnerText = DateTime.UtcNow.ToString(
"yyyy-MM-ddTHH:mm:ss-0000" );
hdr[ "messageId", " " ].InnerText = Context.Request.GetHashCode().ToString();
// get the base calTableUpdate node for data values
XmlNode ctu = msg.GetElementsByTagName( "calTableUpdate" )[0];
// get the base calTableUpdate node for data values
XmlNode tab = msg.GetElementsByTagName( "calibrationFileList" )[0];
// ** set user data values in the message content area
tab[ "transferDirection" ].InnerText = transferDirection.
tab[ "location" ].InnerText = location.Attributes.ToString();
tab[ "logicalName" ].InnerText = logicalName.Attributes.ToString();
tab[ "sizeInKiloBytes" ].InnerText = sizeInKiloBytes.Attributes.ToString();
// ***** get the base calTableUpdate node for data values
XmlNode dil = msg.GetElementsByTagName( "disseminationList" )[0];
// set user data values in the message content area
foreach(ListItem li in disseminationList.Items)
{
if(li.Selected == true)
{
dil[ "disseminationList" ].InnerText = disseminationList.SelectedValue.ToString();
}
}
// submit the document
string rez = ((Global)Context.ApplicationInstance).SoapSubmit( msg, "adrCTU", "hdrCTU" );
// if successful redirect to the refering page
if ( rez == "Success!" ) Response.Redirect( Request.UrlReferrer.AbsoluteUri );
// if error show message
else Response.Write( string.Format(
"<span style=\"FONT-WEIGHT: bold; COLOR: red\">{0}</span>", rez ) );
}
}
}
The following is my XML template:
<?xml version="1.0" encoding="utf-8" ?>
<soap:Envelope xmlns:xsi=" xmlns:xsd=" xmlns:soap=" <soap:Body>
<calTableUpdate xmlns=" <iccHeader>
<messageType xmlns=" <originator xmlns=" ">user</originator>
<originatorAddress xmlns=" <recipient xmlns=" <creationTimeString xmlns=" ">????</creationTimeString>
<messageId xmlns=" ">12345</messageId>
</iccHeader>
<calibrationFileList>
<transferDirection xmlns=" xyz.com ">Push</transferDirection>
<location xmlns=" <logicalName xmlns=" <physicalName xmlns=" <sizeInKiloBytes xmlns=" </calibrationFileList>
<disseminationList>IRS</disseminationList>
</calTableUpdate>
</soap:Body>
</soap:Envelope>
The following is my Excel Spreadsheet generated XML:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<?xml-stylesheet type="text/xsl" href="TC1B_Cal5.xls.xsl"?>
<!-- This XML file is generated by RustemSoft XML Converter Evaluation version -->
<table name="TC1B_Cal">
<TC1B_Cal>
<transferDirection>Push</transferDirection>
<location> <logicalName>12347.txt</logicalName>
<sizeInKiloBytes>20</sizeInKiloBytes>
</TC1B_Cal>
<TC1B_Cal>
<transferDirection>Push</transferDirection>
<location> <logicalName>12348.txt</logicalName>
<sizeInKiloBytes>14</sizeInKiloBytes>
</TC1B_Cal>
<TC1B_Cal>
<transferDirection>Push</transferDirection>
<location> <logicalName>12349.txt</logicalName>
<sizeInKiloBytes>11</sizeInKiloBytes>
</TC1B_Cal>
<TC1B_Cal>
<transferDirection>Push</transferDirection>
<location> <logicalName>12345.txt</logicalName>
<sizeInKiloBytes>8</sizeInKiloBytes>
</TC1B_Cal>
<TC1B_Cal>
<transferDirection>Push</transferDirection>
<location> <logicalName>12346.txt</logicalName>
<sizeInKiloBytes>17</sizeInKiloBytes>
</TC1B_Cal>
</table>
The following is my C# code for the Web form:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Net;
using System.Text;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Xml;
namespace Forms
{
/// <summary>
/// Summary description for Cal_Table_Update_Form.
/// </summary>
public class Cal_Table_Update : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox transferDirection;
protected System.Web.UI.WebControls.TextBox location;
protected System.Web.UI.WebControls.TextBox logicalName;
protected System.Web.UI.HtmlControls.HtmlForm Form1;
protected System.Web.UI.WebControls.TextBox sizeInKiloBytes;
protected System.Web.UI.WebControls.CheckBoxList disseminationList;
protected System.Web.UI.WebControls.Xml calibrationFileList;
protected System.Web.UI.WebControls.Button btnSubmit;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
#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.btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnSubmit_Click(object sender, System.EventArgs e)
{
// load an xml document from the basic soap package file
XmlDocument msg = ((Global)Context.ApplicationInstance).SoapSetup( "xmlCTU" );
// select the header node as a working element
XmlNode hdr = msg.GetElementsByTagName( "iccHeader" )[0];
// set variant data in the header node sub elements
hdr[ "originatorAddress", " ].InnerText = Context.Request.PhysicalPath;
hdr[ "creationTimeString", " " ].InnerText = DateTime.UtcNow.ToString(
"yyyy-MM-ddTHH:mm:ss-0000" );
hdr[ "messageId", " " ].InnerText = Context.Request.GetHashCode().ToString();
// get the base calTableUpdate node for data values
XmlNode ctu = msg.GetElementsByTagName( "calTableUpdate" )[0];
// get the base calTableUpdate node for data values
XmlNode tab = msg.GetElementsByTagName( "calibrationFileList" )[0];
// ** set user data values in the message content area
tab[ "transferDirection" ].InnerText = transferDirection.
tab[ "location" ].InnerText = location.Attributes.ToString();
tab[ "logicalName" ].InnerText = logicalName.Attributes.ToString();
tab[ "sizeInKiloBytes" ].InnerText = sizeInKiloBytes.Attributes.ToString();
// ***** get the base calTableUpdate node for data values
XmlNode dil = msg.GetElementsByTagName( "disseminationList" )[0];
// set user data values in the message content area
foreach(ListItem li in disseminationList.Items)
{
if(li.Selected == true)
{
dil[ "disseminationList" ].InnerText = disseminationList.SelectedValue.ToString();
}
}
// submit the document
string rez = ((Global)Context.ApplicationInstance).SoapSubmit( msg, "adrCTU", "hdrCTU" );
// if successful redirect to the refering page
if ( rez == "Success!" ) Response.Redirect( Request.UrlReferrer.AbsoluteUri );
// if error show message
else Response.Write( string.Format(
"<span style=\"FONT-WEIGHT: bold; COLOR: red\">{0}</span>", rez ) );
}
}
}