473,765 Members | 2,121 Online
Bytes | Software Development & Data Engineering Community
+ 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.Crea te(lcUrl);

string lcPostData =
"XMLData=" + HttpUtility.Url Encode("<Data>T est Data</Data>");

loHttp.Method=" POST";
loHttp.ContentT ype = "applicatio n/x-www-form-urlencoded";
byte [] lbPostBuffer = encoding.GetByt es(lcPostData);
loHttp.ContentL ength = lbPostBuffer.Le ngth;

Stream loPostData = loHttp.GetReque stStream();
loPostData.Writ e(lbPostBuffer, 0,lbPostBuffer. Length);
loPostData.Clos e();

HttpWebResponse loWebResponse = (HttpWebRespons e)
loHttp.GetRespo nse();

Encoding enc = System.Text.Enc oding.GetEncodi ng(1252);

StreamReader loResponseStrea m =
new StreamReader(lo WebResponse.Get ResponseStream( ));

string lcHtml = loResponseStrea m.ReadToEnd();

Response.Write (lcHtml);

loWebResponse.C lose();
loResponseStrea m.Close();

Receiving code:
Stream str = Request.InputSt ream;
int strLen = (int)str.Length ;
byte[] bArr = new byte[strLen];
Int32 bytes = str.Read(bArr,0 ,strLen);
string strmContents = System.Text.Enc oding.ASCII.Get String(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.ContentT ype = "applicatio n/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.Enc oding.ASCII.Get String(bArr);
strXMLData = HttpUtility.Url Decode(strXMLDa ta);
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 1821
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***@discussi ons.microsoft.c om> wrote in message
news:E2******** *************** ***********@mic rosoft.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.Crea te(lcUrl);

string lcPostData =
"XMLData=" + HttpUtility.Url Encode("<Data>T est
Data</Data>");

loHttp.Method=" POST";
loHttp.ContentT ype = "applicatio n/x-www-form-urlencoded";
byte [] lbPostBuffer = encoding.GetByt es(lcPostData);
loHttp.ContentL ength = lbPostBuffer.Le ngth;

Stream loPostData = loHttp.GetReque stStream();
loPostData.Writ e(lbPostBuffer, 0,lbPostBuffer. Length);
loPostData.Clos e();

HttpWebResponse loWebResponse = (HttpWebRespons e)
loHttp.GetRespo nse();

Encoding enc = System.Text.Enc oding.GetEncodi ng(1252);

StreamReader loResponseStrea m =
new StreamReader(lo WebResponse.Get ResponseStream( ));

string lcHtml = loResponseStrea m.ReadToEnd();

Response.Write (lcHtml);

loWebResponse.C lose();
loResponseStrea m.Close();

Receiving code:
Stream str = Request.InputSt ream;
int strLen = (int)str.Length ;
byte[] bArr = new byte[strLen];
Int32 bytes = str.Read(bArr,0 ,strLen);
string strmContents =
System.Text.Enc oding.ASCII.Get String(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.ContentT ype = "applicatio n/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.Enc oding.ASCII.Get String(bArr);
strXMLData = HttpUtility.Url Decode(strXMLDa ta);
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***@discussi ons.microsoft.c om> wrote in message
news:E2******** *************** ***********@mic rosoft.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.Crea te(lcUrl);

string lcPostData =
"XMLData=" + HttpUtility.Url Encode("<Data>T est
Data</Data>");

loHttp.Method=" POST";
loHttp.ContentT ype = "applicatio n/x-www-form-urlencoded";
byte [] lbPostBuffer = encoding.GetByt es(lcPostData);
loHttp.ContentL ength = lbPostBuffer.Le ngth;

Stream loPostData = loHttp.GetReque stStream();
loPostData.Writ e(lbPostBuffer, 0,lbPostBuffer. Length);
loPostData.Clos e();

HttpWebResponse loWebResponse = (HttpWebRespons e)
loHttp.GetRespo nse();

Encoding enc = System.Text.Enc oding.GetEncodi ng(1252);

StreamReader loResponseStrea m =
new StreamReader(lo WebResponse.Get ResponseStream( ));

string lcHtml = loResponseStrea m.ReadToEnd();

Response.Write (lcHtml);

loWebResponse.C lose();
loResponseStrea m.Close();

Receiving code:
Stream str = Request.InputSt ream;
int strLen = (int)str.Length ;
byte[] bArr = new byte[strLen];
Int32 bytes = str.Read(bArr,0 ,strLen);
string strmContents =
System.Text.Enc oding.ASCII.Get String(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.ContentT ype = "applicatio n/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.Enc oding.ASCII.Get String(bArr);
strXMLData = HttpUtility.Url Decode(strXMLDa ta);
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***@discussi ons.microsoft.c om> wrote in message
news:E2******** *************** ***********@mic rosoft.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.Crea te(lcUrl);

string lcPostData =
"XMLData=" + HttpUtility.Url Encode("<Data>T est
Data</Data>");

loHttp.Method=" POST";
loHttp.ContentT ype = "applicatio n/x-www-form-urlencoded";
byte [] lbPostBuffer = encoding.GetByt es(lcPostData);
loHttp.ContentL ength = lbPostBuffer.Le ngth;

Stream loPostData = loHttp.GetReque stStream();
loPostData.Writ e(lbPostBuffer, 0,lbPostBuffer. Length);
loPostData.Clos e();

HttpWebResponse loWebResponse = (HttpWebRespons e)
loHttp.GetRespo nse();

Encoding enc = System.Text.Enc oding.GetEncodi ng(1252);

StreamReader loResponseStrea m =
new StreamReader(lo WebResponse.Get ResponseStream( ));

string lcHtml = loResponseStrea m.ReadToEnd();

Response.Write (lcHtml);

loWebResponse.C lose();
loResponseStrea m.Close();

Receiving code:
Stream str = Request.InputSt ream;
int strLen = (int)str.Length ;
byte[] bArr = new byte[strLen];
Int32 bytes = str.Read(bArr,0 ,strLen);
string strmContents =
System.Text.Enc oding.ASCII.Get String(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.ContentT ype = "applicatio n/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.Enc oding.ASCII.Get String(bArr);
strXMLData = HttpUtility.Url Decode(strXMLDa ta);
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.......ho pe it helps.

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

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"Danny" <Da***@discussi ons.microsoft.c om> wrote in message
news:57******** *************** ***********@mic rosoft.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***@discussi ons.microsoft.c om> wrote in message
news:E2******** *************** ***********@mic rosoft.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.Crea te(lcUrl);
>
> string lcPostData =
> "XMLData=" + HttpUtility.Url Encode("<Data>T est
> Data</Data>");
>
> loHttp.Method=" POST";
> loHttp.ContentT ype = "applicatio n/x-www-form-urlencoded";
> byte [] lbPostBuffer = encoding.GetByt es(lcPostData);
> loHttp.ContentL ength = lbPostBuffer.Le ngth;
>
> Stream loPostData = loHttp.GetReque stStream();
> loPostData.Writ e(lbPostBuffer, 0,lbPostBuffer. Length);
> loPostData.Clos e();
>
> HttpWebResponse loWebResponse = (HttpWebRespons e)
> loHttp.GetRespo nse();
>
> Encoding enc = System.Text.Enc oding.GetEncodi ng(1252);
>
> StreamReader loResponseStrea m =
> new StreamReader(lo WebResponse.Get ResponseStream( ));
>
> string lcHtml = loResponseStrea m.ReadToEnd();
>
> Response.Write (lcHtml);
>
> loWebResponse.C lose();
> loResponseStrea m.Close();
>
> Receiving code:
> Stream str = Request.InputSt ream;
> int strLen = (int)str.Length ;
> byte[] bArr = new byte[strLen];
> Int32 bytes = str.Read(bArr,0 ,strLen);
> string strmContents =
> System.Text.Enc oding.ASCII.Get String(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.ContentT ype = "applicatio n/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.Enc oding.ASCII.Get String(bArr);
> strXMLData = HttpUtility.Url Decode(strXMLDa ta);
> 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***@discussi ons.microsoft.c om> wrote in message
news:E2******** *************** ***********@mic rosoft.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.Crea te(lcUrl);

string lcPostData =
"XMLData=" + HttpUtility.Url Encode("<Data>T est
Data</Data>");

loHttp.Method=" POST";
loHttp.ContentT ype = "applicatio n/x-www-form-urlencoded";
byte [] lbPostBuffer = encoding.GetByt es(lcPostData);
loHttp.ContentL ength = lbPostBuffer.Le ngth;

Stream loPostData = loHttp.GetReque stStream();
loPostData.Writ e(lbPostBuffer, 0,lbPostBuffer. Length);
loPostData.Clos e();

HttpWebResponse loWebResponse = (HttpWebRespons e)
loHttp.GetRespo nse();

Encoding enc = System.Text.Enc oding.GetEncodi ng(1252);

StreamReader loResponseStrea m =
new StreamReader(lo WebResponse.Get ResponseStream( ));

string lcHtml = loResponseStrea m.ReadToEnd();

Response.Write (lcHtml);

loWebResponse.C lose();
loResponseStrea m.Close();

Receiving code:
Stream str = Request.InputSt ream;
int strLen = (int)str.Length ;
byte[] bArr = new byte[strLen];
Int32 bytes = str.Read(bArr,0 ,strLen);
string strmContents =
System.Text.Enc oding.ASCII.Get String(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.ContentT ype = "applicatio n/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.Enc oding.ASCII.Get String(bArr);
strXMLData = HttpUtility.Url Decode(strXMLDa ta);
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
4814
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 receiving! int ret = recvfrom(receivingSocket,szMessage,sizeof(szMessage),0,sockaddr*)&addr_Cli, &clilen); Any ideas?
3
7796
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 received (this is triggered from a class not in the sample code), or if there has been no data on the net for a certain period. During the time where I don't want any packets, I set my socket receive buffer size to zero. The problem is, when I used...
2
3127
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 option and then fire off a thread that calls "receiveFrom()" in a loop. This works sometimes, but other times it'll get into a funk where the "receiveFrom()" call doesn't return even though a packet trace capture (Ethereal) shows that the...
5
10377
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
1344
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 into problems. Sending code: ASCIIEncoding encoding = new ASCIIEncoding(); string lcUrl = "http://localhost/test/receive.aspx"; HttpWebRequest loHttp =
8
16569
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 no problem till here. But also I want to use the incoming data to process it in some functions. But when I assign the incoming string(from the ReadExisting() function) to a local variable there are always lots of characters missing. How do I solve...
7
3189
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 to the console. That data is printed out to the console before I even call Socket.EndReceive(). After that call, I get the rest of the data that wasn't printed out to the console in the buffer. Anyone have any idea what is going on? Here's...
0
596
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 and found (to take with care!) :
0
3583
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 supposed to do the following: monitor ALL INCOMING TCP traffic on the local computer, and save certain parts of it as files - not log files though, but actual files that are sent to the computer as part of http or ftp. Basically if a user browse a page...
0
9568
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
1
9951
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9832
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8831
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7375
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 presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5275
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5419
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.