473,472 Members | 2,153 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Receiving xml problem


I am working on a project in which a number of client applications will be
posting xml documents as a byte array to an ASP.NET page on our web server. I
am trying to simulate the process and run into problems.

Sending code:

ASCIIEncoding encoding = new ASCIIEncoding();

string lcUrl = "http://localhost/test/receive.aspx";
HttpWebRequest loHttp =
(HttpWebRequest) WebRequest.Create(lcUrl);

string lcPostData =
"XMLData=" + HttpUtility.UrlEncode("<Data>Test Data</Data>");

loHttp.Method="POST";
loHttp.ContentType = "application/x-www-form-urlencoded";
byte [] lbPostBuffer = encoding.GetBytes(lcPostData);
loHttp.ContentLength = lbPostBuffer.Length;

Stream loPostData = loHttp.GetRequestStream();
loPostData.Write(lbPostBuffer,0,lbPostBuffer.Lengt h);
loPostData.Close();

HttpWebResponse loWebResponse = (HttpWebResponse)
loHttp.GetResponse();

Encoding enc = System.Text.Encoding.GetEncoding(1252);

StreamReader loResponseStream =
new StreamReader(loWebResponse.GetResponseStream());

string lcHtml = loResponseStream.ReadToEnd();

Response.Write (lcHtml);

loWebResponse.Close();
loResponseStream.Close();

Receiving code:
Stream str = Request.InputStream;
int strLen = (int)str.Length;
byte[] bArr = new byte[strLen];
Int32 bytes = str.Read(bArr,0,strLen);
string strmContents = System.Text.Encoding.ASCII.GetString(bArr,
0, bytes);
Response.Write (strmContents);
The above code will work with XMLData=xyz. But when “<” or “>” is in the
string as above, an error is returned from the receiving page:
The remote server returned an error: (500) Internal Server Error

If the following line is commented out, it works:
loHttp.ContentType = "application/x-www-form-urlencoded";

When it works with the above line commented out, the result displayed is:
XMLData=%3cData%3eTest+Data%3c%2fData%3e

If I use:
string strXMLData = System.Text.Encoding.ASCII.GetString(bArr);
strXMLData = HttpUtility.UrlDecode(strXMLData);
Response.Write (strXMLData);

The result I get is: XMLData=Test Data
I need the end result to be <Data>Test Data</Data>"

Where am I going wrong?

Thanks for any help
Dec 12 '05 #1
5 1809
I dont have an answer for you, but theres an example here that accepts XML
data as a post submission and deserializes it in a web service.

It might help you work out an alternative. Otherwise, I think MVP John
Skeet is the byte array expert in the dotnet.general group.

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"Danny" <Da***@discussions.microsoft.com> wrote in message
news:E2**********************************@microsof t.com...

I am working on a project in which a number of client applications will be
posting xml documents as a byte array to an ASP.NET page on our web
server. I
am trying to simulate the process and run into problems.

Sending code:

ASCIIEncoding encoding = new ASCIIEncoding();

string lcUrl = "http://localhost/test/receive.aspx";
HttpWebRequest loHttp =
(HttpWebRequest) WebRequest.Create(lcUrl);

string lcPostData =
"XMLData=" + HttpUtility.UrlEncode("<Data>Test
Data</Data>");

loHttp.Method="POST";
loHttp.ContentType = "application/x-www-form-urlencoded";
byte [] lbPostBuffer = encoding.GetBytes(lcPostData);
loHttp.ContentLength = lbPostBuffer.Length;

Stream loPostData = loHttp.GetRequestStream();
loPostData.Write(lbPostBuffer,0,lbPostBuffer.Lengt h);
loPostData.Close();

HttpWebResponse loWebResponse = (HttpWebResponse)
loHttp.GetResponse();

Encoding enc = System.Text.Encoding.GetEncoding(1252);

StreamReader loResponseStream =
new StreamReader(loWebResponse.GetResponseStream());

string lcHtml = loResponseStream.ReadToEnd();

Response.Write (lcHtml);

loWebResponse.Close();
loResponseStream.Close();

Receiving code:
Stream str = Request.InputStream;
int strLen = (int)str.Length;
byte[] bArr = new byte[strLen];
Int32 bytes = str.Read(bArr,0,strLen);
string strmContents =
System.Text.Encoding.ASCII.GetString(bArr,
0, bytes);
Response.Write (strmContents);
The above code will work with XMLData=xyz. But when "<" or ">" is in the
string as above, an error is returned from the receiving page:
The remote server returned an error: (500) Internal Server Error

If the following line is commented out, it works:
loHttp.ContentType = "application/x-www-form-urlencoded";

When it works with the above line commented out, the result displayed is:
XMLData=%3cData%3eTest+Data%3c%2fData%3e

If I use:
string strXMLData = System.Text.Encoding.ASCII.GetString(bArr);
strXMLData = HttpUtility.UrlDecode(strXMLData);
Response.Write (strXMLData);

The result I get is: XMLData=Test Data
I need the end result to be <Data>Test Data</Data>"

Where am I going wrong?

Thanks for any help

Dec 12 '05 #2
Thanks John. Can you give me the link to article you suggested.

Regards
Danny

"John Timney ( MVP )" wrote:
I dont have an answer for you, but theres an example here that accepts XML
data as a post submission and deserializes it in a web service.

It might help you work out an alternative. Otherwise, I think MVP John
Skeet is the byte array expert in the dotnet.general group.

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"Danny" <Da***@discussions.microsoft.com> wrote in message
news:E2**********************************@microsof t.com...

I am working on a project in which a number of client applications will be
posting xml documents as a byte array to an ASP.NET page on our web
server. I
am trying to simulate the process and run into problems.

Sending code:

ASCIIEncoding encoding = new ASCIIEncoding();

string lcUrl = "http://localhost/test/receive.aspx";
HttpWebRequest loHttp =
(HttpWebRequest) WebRequest.Create(lcUrl);

string lcPostData =
"XMLData=" + HttpUtility.UrlEncode("<Data>Test
Data</Data>");

loHttp.Method="POST";
loHttp.ContentType = "application/x-www-form-urlencoded";
byte [] lbPostBuffer = encoding.GetBytes(lcPostData);
loHttp.ContentLength = lbPostBuffer.Length;

Stream loPostData = loHttp.GetRequestStream();
loPostData.Write(lbPostBuffer,0,lbPostBuffer.Lengt h);
loPostData.Close();

HttpWebResponse loWebResponse = (HttpWebResponse)
loHttp.GetResponse();

Encoding enc = System.Text.Encoding.GetEncoding(1252);

StreamReader loResponseStream =
new StreamReader(loWebResponse.GetResponseStream());

string lcHtml = loResponseStream.ReadToEnd();

Response.Write (lcHtml);

loWebResponse.Close();
loResponseStream.Close();

Receiving code:
Stream str = Request.InputStream;
int strLen = (int)str.Length;
byte[] bArr = new byte[strLen];
Int32 bytes = str.Read(bArr,0,strLen);
string strmContents =
System.Text.Encoding.ASCII.GetString(bArr,
0, bytes);
Response.Write (strmContents);
The above code will work with XMLData=xyz. But when "<" or ">" is in the
string as above, an error is returned from the receiving page:
The remote server returned an error: (500) Internal Server Error

If the following line is commented out, it works:
loHttp.ContentType = "application/x-www-form-urlencoded";

When it works with the above line commented out, the result displayed is:
XMLData=%3cData%3eTest+Data%3c%2fData%3e

If I use:
string strXMLData = System.Text.Encoding.ASCII.GetString(bArr);
strXMLData = HttpUtility.UrlDecode(strXMLData);
Response.Write (strXMLData);

The result I get is: XMLData=Test Data
I need the end result to be <Data>Test Data</Data>"

Where am I going wrong?

Thanks for any help


Dec 12 '05 #3
you need to turn validateRequest off for this page. by default, asp.net
throws an error if a "<" is found in the form data. this is to handle bady
coded sites that allow script injection.

-- bruce (sqlwork.com)

"Danny" <Da***@discussions.microsoft.com> wrote in message
news:E2**********************************@microsof t.com...

I am working on a project in which a number of client applications will be
posting xml documents as a byte array to an ASP.NET page on our web
server. I
am trying to simulate the process and run into problems.

Sending code:

ASCIIEncoding encoding = new ASCIIEncoding();

string lcUrl = "http://localhost/test/receive.aspx";
HttpWebRequest loHttp =
(HttpWebRequest) WebRequest.Create(lcUrl);

string lcPostData =
"XMLData=" + HttpUtility.UrlEncode("<Data>Test
Data</Data>");

loHttp.Method="POST";
loHttp.ContentType = "application/x-www-form-urlencoded";
byte [] lbPostBuffer = encoding.GetBytes(lcPostData);
loHttp.ContentLength = lbPostBuffer.Length;

Stream loPostData = loHttp.GetRequestStream();
loPostData.Write(lbPostBuffer,0,lbPostBuffer.Lengt h);
loPostData.Close();

HttpWebResponse loWebResponse = (HttpWebResponse)
loHttp.GetResponse();

Encoding enc = System.Text.Encoding.GetEncoding(1252);

StreamReader loResponseStream =
new StreamReader(loWebResponse.GetResponseStream());

string lcHtml = loResponseStream.ReadToEnd();

Response.Write (lcHtml);

loWebResponse.Close();
loResponseStream.Close();

Receiving code:
Stream str = Request.InputStream;
int strLen = (int)str.Length;
byte[] bArr = new byte[strLen];
Int32 bytes = str.Read(bArr,0,strLen);
string strmContents =
System.Text.Encoding.ASCII.GetString(bArr,
0, bytes);
Response.Write (strmContents);
The above code will work with XMLData=xyz. But when "<" or ">" is in the
string as above, an error is returned from the receiving page:
The remote server returned an error: (500) Internal Server Error

If the following line is commented out, it works:
loHttp.ContentType = "application/x-www-form-urlencoded";

When it works with the above line commented out, the result displayed is:
XMLData=%3cData%3eTest+Data%3c%2fData%3e

If I use:
string strXMLData = System.Text.Encoding.ASCII.GetString(bArr);
strXMLData = HttpUtility.UrlDecode(strXMLData);
Response.Write (strXMLData);

The result I get is: XMLData=Test Data
I need the end result to be <Data>Test Data</Data>"

Where am I going wrong?

Thanks for any help

Dec 12 '05 #4
Sorry, heres the link, you might not need it with Bruces answer
though.......hope it helps.

http://www.prescod.net/rest/dotnet/

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"Danny" <Da***@discussions.microsoft.com> wrote in message
news:57**********************************@microsof t.com...
Thanks John. Can you give me the link to article you suggested.

Regards
Danny

"John Timney ( MVP )" wrote:
I dont have an answer for you, but theres an example here that accepts
XML
data as a post submission and deserializes it in a web service.

It might help you work out an alternative. Otherwise, I think MVP John
Skeet is the byte array expert in the dotnet.general group.

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"Danny" <Da***@discussions.microsoft.com> wrote in message
news:E2**********************************@microsof t.com...
>
> I am working on a project in which a number of client applications will
> be
> posting xml documents as a byte array to an ASP.NET page on our web
> server. I
> am trying to simulate the process and run into problems.
>
> Sending code:
>
> ASCIIEncoding encoding = new ASCIIEncoding();
>
> string lcUrl = "http://localhost/test/receive.aspx";
> HttpWebRequest loHttp =
> (HttpWebRequest) WebRequest.Create(lcUrl);
>
> string lcPostData =
> "XMLData=" + HttpUtility.UrlEncode("<Data>Test
> Data</Data>");
>
> loHttp.Method="POST";
> loHttp.ContentType = "application/x-www-form-urlencoded";
> byte [] lbPostBuffer = encoding.GetBytes(lcPostData);
> loHttp.ContentLength = lbPostBuffer.Length;
>
> Stream loPostData = loHttp.GetRequestStream();
> loPostData.Write(lbPostBuffer,0,lbPostBuffer.Lengt h);
> loPostData.Close();
>
> HttpWebResponse loWebResponse = (HttpWebResponse)
> loHttp.GetResponse();
>
> Encoding enc = System.Text.Encoding.GetEncoding(1252);
>
> StreamReader loResponseStream =
> new StreamReader(loWebResponse.GetResponseStream());
>
> string lcHtml = loResponseStream.ReadToEnd();
>
> Response.Write (lcHtml);
>
> loWebResponse.Close();
> loResponseStream.Close();
>
> Receiving code:
> Stream str = Request.InputStream;
> int strLen = (int)str.Length;
> byte[] bArr = new byte[strLen];
> Int32 bytes = str.Read(bArr,0,strLen);
> string strmContents =
> System.Text.Encoding.ASCII.GetString(bArr,
> 0, bytes);
> Response.Write (strmContents);
>
>
> The above code will work with XMLData=xyz. But when "<" or ">" is in
> the
> string as above, an error is returned from the receiving page:
> The remote server returned an error: (500) Internal Server Error
>
> If the following line is commented out, it works:
> loHttp.ContentType = "application/x-www-form-urlencoded";
>
> When it works with the above line commented out, the result displayed
> is:
> XMLData=%3cData%3eTest+Data%3c%2fData%3e
>
> If I use:
> string strXMLData =
> System.Text.Encoding.ASCII.GetString(bArr);
> strXMLData = HttpUtility.UrlDecode(strXMLData);
> Response.Write (strXMLData);
>
> The result I get is: XMLData=Test Data
> I need the end result to be <Data>Test Data</Data>"
>
> Where am I going wrong?
>
> Thanks for any help
>
>


Dec 12 '05 #5
Hi Bruce

I tried what you said and still get the error. What would be the most common
approach for sending xml documents from multiple clients to a server?

Thanks
Danny

"Bruce Barker" wrote:
you need to turn validateRequest off for this page. by default, asp.net
throws an error if a "<" is found in the form data. this is to handle bady
coded sites that allow script injection.

-- bruce (sqlwork.com)

"Danny" <Da***@discussions.microsoft.com> wrote in message
news:E2**********************************@microsof t.com...

I am working on a project in which a number of client applications will be
posting xml documents as a byte array to an ASP.NET page on our web
server. I
am trying to simulate the process and run into problems.

Sending code:

ASCIIEncoding encoding = new ASCIIEncoding();

string lcUrl = "http://localhost/test/receive.aspx";
HttpWebRequest loHttp =
(HttpWebRequest) WebRequest.Create(lcUrl);

string lcPostData =
"XMLData=" + HttpUtility.UrlEncode("<Data>Test
Data</Data>");

loHttp.Method="POST";
loHttp.ContentType = "application/x-www-form-urlencoded";
byte [] lbPostBuffer = encoding.GetBytes(lcPostData);
loHttp.ContentLength = lbPostBuffer.Length;

Stream loPostData = loHttp.GetRequestStream();
loPostData.Write(lbPostBuffer,0,lbPostBuffer.Lengt h);
loPostData.Close();

HttpWebResponse loWebResponse = (HttpWebResponse)
loHttp.GetResponse();

Encoding enc = System.Text.Encoding.GetEncoding(1252);

StreamReader loResponseStream =
new StreamReader(loWebResponse.GetResponseStream());

string lcHtml = loResponseStream.ReadToEnd();

Response.Write (lcHtml);

loWebResponse.Close();
loResponseStream.Close();

Receiving code:
Stream str = Request.InputStream;
int strLen = (int)str.Length;
byte[] bArr = new byte[strLen];
Int32 bytes = str.Read(bArr,0,strLen);
string strmContents =
System.Text.Encoding.ASCII.GetString(bArr,
0, bytes);
Response.Write (strmContents);
The above code will work with XMLData=xyz. But when "<" or ">" is in the
string as above, an error is returned from the receiving page:
The remote server returned an error: (500) Internal Server Error

If the following line is commented out, it works:
loHttp.ContentType = "application/x-www-form-urlencoded";

When it works with the above line commented out, the result displayed is:
XMLData=%3cData%3eTest+Data%3c%2fData%3e

If I use:
string strXMLData = System.Text.Encoding.ASCII.GetString(bArr);
strXMLData = HttpUtility.UrlDecode(strXMLData);
Response.Write (strXMLData);

The result I get is: XMLData=Test Data
I need the end result to be <Data>Test Data</Data>"

Where am I going wrong?

Thanks for any help


Dec 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ramiro Barbosa, Jr. | last post by:
All, In regards to the call below, I was wondering why is it that the 'szMessage' receiving buffer results in an empty one, but by printing 'ret' it indicates the number of bytes I am indeed...
3
by: Stephan Steiner | last post by:
Hi I have a small program listening to UDP broadcast datagrams that are periodically sent out. It will stop listening for a certain period if either a sufficient number of packets has been...
2
by: Terry | last post by:
I've got a strange problem receiving multicast packets in a C# application. What's strange is that it works *sometimes* but not always. I create a socket, call bind(), set the multicast socket...
5
by: LS | last post by:
Can a WebMethod return an Interface type? Can we pass an interface parameter ? Example : public interface IEntity { long Id { get; set; } string Name { get; set; } }
0
by: Danny | last post by:
I am working on a project in which a number of client applications will be posting xml documents as a byte array to an ASP.NET page on our web server. I am trying to simulate the process and run...
8
by: dadalos | last post by:
Hello; I'm having a problem with receiving data from serial port. There's an eventhandler(datareceived) and I'm monitoring the answer from the serial port to a text box in the eventhandler. There's...
7
by: darthghandi | last post by:
I am having mixed results with asynchronous socket receives. Sometimes I get the right information back from the buffer, other times I get some of the data that should be in the buffer printed out...
0
by: pauland80 | last post by:
<snip> <snip> Late thanks for your both answers! (Please excuse me for that) The problem was a bug in the device firmware. But before finding this, I dugg lightly in the pyserial source...
0
by: george585 | last post by:
Hello! I am new to network programming, and understand just basics. Using some sample code, and having read documentation, I managed to create a simple app in C# and VB.NET. The application is...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.