469,927 Members | 1,464 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

Sending a XML document via HTTP

I'm new to XML.

I need to have my asp.net page accept an XML document sent
via HTTP (from a Java app), process some info and send
back a response as XML.

I continue to get back an error on my web page:
The data at the root level is invalid. Line 1, position 1.

Currently, I am running the XML document through the class
XmlDocument (so I can read the the line <?xml
version="1.0" encoding="UTF-8">), saving it to a file on
my server then opening it with XmlTextReader to read and
process some info, and then responding back with XML.

Thanks in advance. I've been stuggling with this for a
while and would appreciate any help.

My .aspx page
<HTML>
<HEAD>
<title>Test Page</title>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<%
string strXML = doCallProcessRequest(m_strRequest);
output.InnerHtml = strXML;
%>
<font size="5" color="#02027a">Reading XML
Document</font>
<div id="output" runat="server" />
</form>
</body>
</HTML>

My Codebehind:

private void Page_Load(object sender, System.EventArgs e)
{
m_strRequest = Server.HtmlEncode
(Request.QueryString.GetValues("value")[0]);
}

public string doCallProcessRequest(string strXML)
{
//Create the XmlDocument that was passed in on the URL
XmlDocument myXmlDocument = new XmlDocument();
myXmlDocument.LoadXml(strXML);

// Save the document to a file so we can use the
XmlTextReader
myXmlDocument.Save(Server.MapPath
("Files\\Request.xml"));

// retrieve UserID/Password via XMLTextReader from the
above file

// Test if a valid User
KYCSecurity objSecurity = new KYCSecurity();

bool bRet = objSecurity.IsValidUser(strUserID,
strPassword);
if (bRet)
{
// build this XML string here
string strXMLResponse="";

return strXMLResponse;
}
else
{
// Invalid UserID and/or Password
return "Invalid UserID and/or Password";
}
}
Input:
<?xml version="1.0" encoding="UTF-8"?>
<Request xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance" xsi:noNamespaceSchemaLocation="C:\_Test\Request
Message - Account.xsd" id="YYY" password="XXX"
RequestType="ADD">
<Account>
<ID>101</ID>
<AcctNum>12345</AcctNum>
<CurrencyCode>50</CurrencyCode>
<AcctName>Dummy Account Name</AcctName>
<AcctPurpose>Sample Purpose</AcctPurpose>
<AvgPaymentValue>Sample</AvgPaymentValue>
<AvgPaymentVolume>Sample</AvgPaymentVolume>
<AvgBalance>Sample</AvgBalance>
</Account>
</Request>

Output:
<?xml version="1.0" encoding="UTF-8"?>
<ResponseList xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance" xsi:noNamespaceSchemaLocation="C:\_Test\Response
Message.xsd">
<Response>
<StatusList>
<Status>
<Code>5</Code>
<Description>OK</Description>
</Status>
</StatusList>
<ErrorList>
<Error>
<Code>1000</Code>
<Description>Sample Warning or
Error</Description>
</Error>
</ErrorList>
<ReturnDataList>
<ReturnData>
<Name>ID</Name>
<Value>1234567890</Value>
</ReturnData>
<ReturnData>
<Name>STATUS</Name>
<Value>Complete</Value>
</ReturnData>
</ReturnDataList>
</Response>
</ResponseList>

Nov 11 '05 #1
2 2937
Do a regular html form request and

handicraft your server acceptance.

----------

the Ms way (there is none),

otherwise will cost you (http)


"Robert" <pr*****@noemailspecified.com> wrote in message
news:3a****************************@phx.gbl...
I'm new to XML.

I need to have my asp.net page accept an XML document sent
via HTTP (from a Java app), process some info and send
back a response as XML.

I continue to get back an error on my web page:
The data at the root level is invalid. Line 1, position 1.

Currently, I am running the XML document through the class
XmlDocument (so I can read the the line <?xml
version="1.0" encoding="UTF-8">), saving it to a file on
my server then opening it with XmlTextReader to read and
process some info, and then responding back with XML.

Thanks in advance. I've been stuggling with this for a
while and would appreciate any help.

My .aspx page
<HTML>
<HEAD>
<title>Test Page</title>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<%
string strXML = doCallProcessRequest(m_strRequest);
output.InnerHtml = strXML;
%>
<font size="5" color="#02027a">Reading XML
Document</font>
<div id="output" runat="server" />
</form>
</body>
</HTML>

My Codebehind:

private void Page_Load(object sender, System.EventArgs e)
{
m_strRequest = Server.HtmlEncode
(Request.QueryString.GetValues("value")[0]);
}

public string doCallProcessRequest(string strXML)
{
//Create the XmlDocument that was passed in on the URL
XmlDocument myXmlDocument = new XmlDocument();
myXmlDocument.LoadXml(strXML);

// Save the document to a file so we can use the
XmlTextReader
myXmlDocument.Save(Server.MapPath
("Files\\Request.xml"));

// retrieve UserID/Password via XMLTextReader from the
above file

// Test if a valid User
KYCSecurity objSecurity = new KYCSecurity();

bool bRet = objSecurity.IsValidUser(strUserID,
strPassword);
if (bRet)
{
// build this XML string here
string strXMLResponse="";

return strXMLResponse;
}
else
{
// Invalid UserID and/or Password
return "Invalid UserID and/or Password";
}
}
Input:
<?xml version="1.0" encoding="UTF-8"?>
<Request xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance" xsi:noNamespaceSchemaLocation="C:\_Test\Request
Message - Account.xsd" id="YYY" password="XXX"
RequestType="ADD">
<Account>
<ID>101</ID>
<AcctNum>12345</AcctNum>
<CurrencyCode>50</CurrencyCode>
<AcctName>Dummy Account Name</AcctName>
<AcctPurpose>Sample Purpose</AcctPurpose>
<AvgPaymentValue>Sample</AvgPaymentValue>
<AvgPaymentVolume>Sample</AvgPaymentVolume>
<AvgBalance>Sample</AvgBalance>
</Account>
</Request>

Output:
<?xml version="1.0" encoding="UTF-8"?>
<ResponseList xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance" xsi:noNamespaceSchemaLocation="C:\_Test\Response
Message.xsd">
<Response>
<StatusList>
<Status>
<Code>5</Code>
<Description>OK</Description>
</Status>
</StatusList>
<ErrorList>
<Error>
<Code>1000</Code>
<Description>Sample Warning or
Error</Description>
</Error>
</ErrorList>
<ReturnDataList>
<ReturnData>
<Name>ID</Name>
<Value>1234567890</Value>
</ReturnData>
<ReturnData>
<Name>STATUS</Name>
<Value>Complete</Value>
</ReturnData>
</ReturnDataList>
</Response>
</ResponseList>


Nov 11 '05 #2
If you use stream object instead of string, everything should work just fine
for you. Or change the Encoding of the output document from UTF-8 to
UTF-16.

Howard Hao.

--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm.
"Robert" <pr*****@noemailspecified.com> wrote in message
news:3a****************************@phx.gbl...
I'm new to XML.

I need to have my asp.net page accept an XML document sent
via HTTP (from a Java app), process some info and send
back a response as XML.

I continue to get back an error on my web page:
The data at the root level is invalid. Line 1, position 1.

Currently, I am running the XML document through the class
XmlDocument (so I can read the the line <?xml
version="1.0" encoding="UTF-8">), saving it to a file on
my server then opening it with XmlTextReader to read and
process some info, and then responding back with XML.

Thanks in advance. I've been stuggling with this for a
while and would appreciate any help.

My .aspx page
<HTML>
<HEAD>
<title>Test Page</title>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<%
string strXML = doCallProcessRequest(m_strRequest);
output.InnerHtml = strXML;
%>
<font size="5" color="#02027a">Reading XML
Document</font>
<div id="output" runat="server" />
</form>
</body>
</HTML>

My Codebehind:

private void Page_Load(object sender, System.EventArgs e)
{
m_strRequest = Server.HtmlEncode
(Request.QueryString.GetValues("value")[0]);
}

public string doCallProcessRequest(string strXML)
{
//Create the XmlDocument that was passed in on the URL
XmlDocument myXmlDocument = new XmlDocument();
myXmlDocument.LoadXml(strXML);

// Save the document to a file so we can use the
XmlTextReader
myXmlDocument.Save(Server.MapPath
("Files\\Request.xml"));

// retrieve UserID/Password via XMLTextReader from the
above file

// Test if a valid User
KYCSecurity objSecurity = new KYCSecurity();

bool bRet = objSecurity.IsValidUser(strUserID,
strPassword);
if (bRet)
{
// build this XML string here
string strXMLResponse="";

return strXMLResponse;
}
else
{
// Invalid UserID and/or Password
return "Invalid UserID and/or Password";
}
}
Input:
<?xml version="1.0" encoding="UTF-8"?>
<Request xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance" xsi:noNamespaceSchemaLocation="C:\_Test\Request
Message - Account.xsd" id="YYY" password="XXX"
RequestType="ADD">
<Account>
<ID>101</ID>
<AcctNum>12345</AcctNum>
<CurrencyCode>50</CurrencyCode>
<AcctName>Dummy Account Name</AcctName>
<AcctPurpose>Sample Purpose</AcctPurpose>
<AvgPaymentValue>Sample</AvgPaymentValue>
<AvgPaymentVolume>Sample</AvgPaymentVolume>
<AvgBalance>Sample</AvgBalance>
</Account>
</Request>

Output:
<?xml version="1.0" encoding="UTF-8"?>
<ResponseList xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance" xsi:noNamespaceSchemaLocation="C:\_Test\Response
Message.xsd">
<Response>
<StatusList>
<Status>
<Code>5</Code>
<Description>OK</Description>
</Status>
</StatusList>
<ErrorList>
<Error>
<Code>1000</Code>
<Description>Sample Warning or
Error</Description>
</Error>
</ErrorList>
<ReturnDataList>
<ReturnData>
<Name>ID</Name>
<Value>1234567890</Value>
</ReturnData>
<ReturnData>
<Name>STATUS</Name>
<Value>Complete</Value>
</ReturnData>
</ReturnDataList>
</Response>
</ResponseList>

Nov 11 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by John Chen | last post: by
3 posts views Thread by Emily John | last post: by
3 posts views Thread by Dave | last post: by
13 posts views Thread by yawnmoth | last post: by
7 posts views Thread by bleachie | last post: by
2 posts views Thread by lstanikmas | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.