By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,423 Members | 2,466 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,423 IT Pros & Developers. It's quick & easy.

byte array problem

P: n/a
I am working on a project where I will receive xml documents from clients
machines as a byte array. They will use the web browser navigate method to
post the data to my ASP.NET page. I then pick up the byte array using the
request object (XMLData=bytearray..). Can someone point me to an article that
shows me how I can do this in ASP.NET, C#?

Thanks
Danny
Dec 1 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Convert the byte array to a string. Create an XmlDocument instance, and use
the Load() method, passing the string to the constructor.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition

"Danny" <Da***@discussions.microsoft.com> wrote in message
news:97**********************************@microsof t.com...
I am working on a project where I will receive xml documents from clients
machines as a byte array. They will use the web browser navigate method to
post the data to my ASP.NET page. I then pick up the byte array using the
request object (XMLData=bytearray..). Can someone point me to an article
that
shows me how I can do this in ASP.NET, C#?

Thanks
Danny

Dec 1 '05 #2

P: n/a
Thanks Kevin

To receive the byte array from the client should I be using
Request.InputStream ?

Assuming the method I think the clients will use to send the data to my
application, could be like this:

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

// *** Send any POST data
string lcPostData =
"XMLData=" + HttpUtility.UrlEncode("xmldata..");

loHttp.Method="POST";
byte [] lbPostBuffer =
System.Text.Encoding.GetEncoding(1252).GetBytes(lc PostData);
loHttp.ContentLength = lbPostBuffer.Length;
"Kevin Spencer" wrote:
Convert the byte array to a string. Create an XmlDocument instance, and use
the Load() method, passing the string to the constructor.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition

"Danny" <Da***@discussions.microsoft.com> wrote in message
news:97**********************************@microsof t.com...
I am working on a project where I will receive xml documents from clients
machines as a byte array. They will use the web browser navigate method to
post the data to my ASP.NET page. I then pick up the byte array using the
request object (XMLData=bytearray..). Can someone point me to an article
that
shows me how I can do this in ASP.NET, C#?

Thanks
Danny


Dec 1 '05 #3

P: n/a
Hi Danny,

If I understand you correctly, they are using a .Net program that employs
the HttpWebRequest to send the XML data via HTTP POST?

If so, you need to create an HTML form on the fly so to speak. This is not
too hard to do. An HTTP Post is a sequence of "name=value" pairs, separated
by '&' characters, just like a QueryString, but longer. The "name" part is
the name of a form field, and the "value" part is the data for that form
field. So, for example, if you wanted to POST a form having one field named
"foo" and the value in it was "bar" your body would simply look like this:

foo=bar

Of course, this must all be URLEncoded, and sending an XML document means a
lot of URLEncoding, for all the tags and such, but using URLEncode() will do
it. So, to send a single XML document via POST would be something like:

string body = "Xml=" + HttpUtility.URLEncode(XmlString);

"Xml" would be the name of the form field.

It has to be encoded into a byte array because you are actually sending a
stream, but it becomes a string at the other end. So, your code might look
something like the following:

ASCIIEncoding encoding = new ASCIIEncoding();
Stream requestStream = null;
string lcUrl = "http://localhost/test/receive.aspx";
HttpWebRequest IoHttp = (HttpWebRequest) WebRequest.Create(lcUrl);
IoHttp.Method = "POST";
IoHttp.ContentType = "application/x-www-form-urlencoded";
string body = encoding.GetBytes("Xml=" + HttpUtility.URLEncode(XmlString));
IoHttp.ContentLength = body.Length;
try
{
requestStream = IoHttp.GetRequestStream();
requestStream.Write(body, 0, body.Length);
}
catch
{
//...
}
finally
{
if (requestStream != null) requestStream.Close();
}

In your ASPX page, you just get Request.Form["Xml"] which is already a
string.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition

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

To receive the byte array from the client should I be using
Request.InputStream ?

Assuming the method I think the clients will use to send the data to my
application, could be like this:

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

// *** Send any POST data
string lcPostData =
"XMLData=" + HttpUtility.UrlEncode("xmldata..");

loHttp.Method="POST";
byte [] lbPostBuffer =
System.Text.Encoding.GetEncoding(1252).GetBytes(lc PostData);
loHttp.ContentLength = lbPostBuffer.Length;
"Kevin Spencer" wrote:
Convert the byte array to a string. Create an XmlDocument instance, and
use
the Load() method, passing the string to the constructor.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition

"Danny" <Da***@discussions.microsoft.com> wrote in message
news:97**********************************@microsof t.com...
>I am working on a project where I will receive xml documents from
>clients
> machines as a byte array. They will use the web browser navigate method
> to
> post the data to my ASP.NET page. I then pick up the byte array using
> the
> request object (XMLData=bytearray..). Can someone point me to an
> article
> that
> shows me how I can do this in ASP.NET, C#?
>
> Thanks
> Danny


Dec 1 '05 #4

P: n/a
Kevin thanks alot for your help. One quick question regarding this.
They will be using a .net program to post the xml data with the web browser
method. Will this still work with what you said?

Regards
Danny
"Kevin Spencer" wrote:
Hi Danny,

If I understand you correctly, they are using a .Net program that employs
the HttpWebRequest to send the XML data via HTTP POST?

If so, you need to create an HTML form on the fly so to speak. This is not
too hard to do. An HTTP Post is a sequence of "name=value" pairs, separated
by '&' characters, just like a QueryString, but longer. The "name" part is
the name of a form field, and the "value" part is the data for that form
field. So, for example, if you wanted to POST a form having one field named
"foo" and the value in it was "bar" your body would simply look like this:

foo=bar

Of course, this must all be URLEncoded, and sending an XML document means a
lot of URLEncoding, for all the tags and such, but using URLEncode() will do
it. So, to send a single XML document via POST would be something like:

string body = "Xml=" + HttpUtility.URLEncode(XmlString);

"Xml" would be the name of the form field.

It has to be encoded into a byte array because you are actually sending a
stream, but it becomes a string at the other end. So, your code might look
something like the following:

ASCIIEncoding encoding = new ASCIIEncoding();
Stream requestStream = null;
string lcUrl = "http://localhost/test/receive.aspx";
HttpWebRequest IoHttp = (HttpWebRequest) WebRequest.Create(lcUrl);
IoHttp.Method = "POST";
IoHttp.ContentType = "application/x-www-form-urlencoded";
string body = encoding.GetBytes("Xml=" + HttpUtility.URLEncode(XmlString));
IoHttp.ContentLength = body.Length;
try
{
requestStream = IoHttp.GetRequestStream();
requestStream.Write(body, 0, body.Length);
}
catch
{
//...
}
finally
{
if (requestStream != null) requestStream.Close();
}

In your ASPX page, you just get Request.Form["Xml"] which is already a
string.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition

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

To receive the byte array from the client should I be using
Request.InputStream ?

Assuming the method I think the clients will use to send the data to my
application, could be like this:

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

// *** Send any POST data
string lcPostData =
"XMLData=" + HttpUtility.UrlEncode("xmldata..");

loHttp.Method="POST";
byte [] lbPostBuffer =
System.Text.Encoding.GetEncoding(1252).GetBytes(lc PostData);
loHttp.ContentLength = lbPostBuffer.Length;
"Kevin Spencer" wrote:
Convert the byte array to a string. Create an XmlDocument instance, and
use
the Load() method, passing the string to the constructor.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition

"Danny" <Da***@discussions.microsoft.com> wrote in message
news:97**********************************@microsof t.com...
>I am working on a project where I will receive xml documents from
>clients
> machines as a byte array. They will use the web browser navigate method
> to
> post the data to my ASP.NET page. I then pick up the byte array using
> the
> request object (XMLData=bytearray..). Can someone point me to an
> article
> that
> shows me how I can do this in ASP.NET, C#?
>
> Thanks
> Danny


Dec 2 '05 #5

P: n/a
Hi Kevin

I tried what you said but get an error saying cannot implicitly convert type
Byte[] to string,
string body = encoding.GetBytes("Xml=" + HttpUtility.UrlEncode(XmlString));

I changed it the string body to byte [] and it worked fine when
Xml="sdfdsfsfsd", but when I put a "<" in the xml string an error occurs :
The remote server returned an error: (500) Internal Server Error.

Can you see what could be causing this?

Thanks
Danny

"Kevin Spencer" wrote:
Hi Danny,

If I understand you correctly, they are using a .Net program that employs
the HttpWebRequest to send the XML data via HTTP POST?

If so, you need to create an HTML form on the fly so to speak. This is not
too hard to do. An HTTP Post is a sequence of "name=value" pairs, separated
by '&' characters, just like a QueryString, but longer. The "name" part is
the name of a form field, and the "value" part is the data for that form
field. So, for example, if you wanted to POST a form having one field named
"foo" and the value in it was "bar" your body would simply look like this:

foo=bar

Of course, this must all be URLEncoded, and sending an XML document means a
lot of URLEncoding, for all the tags and such, but using URLEncode() will do
it. So, to send a single XML document via POST would be something like:

string body = "Xml=" + HttpUtility.URLEncode(XmlString);

"Xml" would be the name of the form field.

It has to be encoded into a byte array because you are actually sending a
stream, but it becomes a string at the other end. So, your code might look
something like the following:

ASCIIEncoding encoding = new ASCIIEncoding();
Stream requestStream = null;
string lcUrl = "http://localhost/test/receive.aspx";
HttpWebRequest IoHttp = (HttpWebRequest) WebRequest.Create(lcUrl);
IoHttp.Method = "POST";
IoHttp.ContentType = "application/x-www-form-urlencoded";
string body = encoding.GetBytes("Xml=" + HttpUtility.URLEncode(XmlString));
IoHttp.ContentLength = body.Length;
try
{
requestStream = IoHttp.GetRequestStream();
requestStream.Write(body, 0, body.Length);
}
catch
{
//...
}
finally
{
if (requestStream != null) requestStream.Close();
}

In your ASPX page, you just get Request.Form["Xml"] which is already a
string.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition

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

To receive the byte array from the client should I be using
Request.InputStream ?

Assuming the method I think the clients will use to send the data to my
application, could be like this:

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

// *** Send any POST data
string lcPostData =
"XMLData=" + HttpUtility.UrlEncode("xmldata..");

loHttp.Method="POST";
byte [] lbPostBuffer =
System.Text.Encoding.GetEncoding(1252).GetBytes(lc PostData);
loHttp.ContentLength = lbPostBuffer.Length;
"Kevin Spencer" wrote:
Convert the byte array to a string. Create an XmlDocument instance, and
use
the Load() method, passing the string to the constructor.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition

"Danny" <Da***@discussions.microsoft.com> wrote in message
news:97**********************************@microsof t.com...
>I am working on a project where I will receive xml documents from
>clients
> machines as a byte array. They will use the web browser navigate method
> to
> post the data to my ASP.NET page. I then pick up the byte array using
> the
> request object (XMLData=bytearray..). Can someone point me to an
> article
> that
> shows me how I can do this in ASP.NET, C#?
>
> Thanks
> Danny


Dec 2 '05 #6

P: n/a
Hi Danny,

It doesn't matter what software the client is using. An HTTP message is an
HTTP message, and that is all that will arrive at the server. Good luck!

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a horse to water,
but you can't make him think.

"Danny" <Da***@discussions.microsoft.com> wrote in message
news:F2**********************************@microsof t.com...
Kevin thanks alot for your help. One quick question regarding this.
They will be using a .net program to post the xml data with the web
browser
method. Will this still work with what you said?

Regards
Danny
"Kevin Spencer" wrote:
Hi Danny,

If I understand you correctly, they are using a .Net program that employs
the HttpWebRequest to send the XML data via HTTP POST?

If so, you need to create an HTML form on the fly so to speak. This is
not
too hard to do. An HTTP Post is a sequence of "name=value" pairs,
separated
by '&' characters, just like a QueryString, but longer. The "name" part
is
the name of a form field, and the "value" part is the data for that form
field. So, for example, if you wanted to POST a form having one field
named
"foo" and the value in it was "bar" your body would simply look like
this:

foo=bar

Of course, this must all be URLEncoded, and sending an XML document means
a
lot of URLEncoding, for all the tags and such, but using URLEncode() will
do
it. So, to send a single XML document via POST would be something like:

string body = "Xml=" + HttpUtility.URLEncode(XmlString);

"Xml" would be the name of the form field.

It has to be encoded into a byte array because you are actually sending a
stream, but it becomes a string at the other end. So, your code might
look
something like the following:

ASCIIEncoding encoding = new ASCIIEncoding();
Stream requestStream = null;
string lcUrl = "http://localhost/test/receive.aspx";
HttpWebRequest IoHttp = (HttpWebRequest) WebRequest.Create(lcUrl);
IoHttp.Method = "POST";
IoHttp.ContentType = "application/x-www-form-urlencoded";
string body = encoding.GetBytes("Xml=" +
HttpUtility.URLEncode(XmlString));
IoHttp.ContentLength = body.Length;
try
{
requestStream = IoHttp.GetRequestStream();
requestStream.Write(body, 0, body.Length);
}
catch
{
//...
}
finally
{
if (requestStream != null) requestStream.Close();
}

In your ASPX page, you just get Request.Form["Xml"] which is already a
string.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition

"Danny" <Da***@discussions.microsoft.com> wrote in message
news:A5**********************************@microsof t.com...
> Thanks Kevin
>
> To receive the byte array from the client should I be using
> Request.InputStream ?
>
> Assuming the method I think the clients will use to send the data to my
> application, could be like this:
>
> string lcUrl = "http://localhost/test/receive.aspx";
> HttpWebRequest loHttp =
> (HttpWebRequest) WebRequest.Create(lcUrl);
>
> // *** Send any POST data
> string lcPostData =
> "XMLData=" + HttpUtility.UrlEncode("xmldata..");
>
> loHttp.Method="POST";
> byte [] lbPostBuffer =
> System.Text.Encoding.GetEncoding(1252).GetBytes(lc PostData);
> loHttp.ContentLength = lbPostBuffer.Length;
>
>
> "Kevin Spencer" wrote:
>
>> Convert the byte array to a string. Create an XmlDocument instance,
>> and
>> use
>> the Load() method, passing the string to the constructor.
>>
>> --
>> HTH,
>>
>> Kevin Spencer
>> Microsoft MVP
>> ..Net Developer
>> If you push something hard enough,
>> it will fall over.
>> - Fudd's First Law of Opposition
>>
>> "Danny" <Da***@discussions.microsoft.com> wrote in message
>> news:97**********************************@microsof t.com...
>> >I am working on a project where I will receive xml documents from
>> >clients
>> > machines as a byte array. They will use the web browser navigate
>> > method
>> > to
>> > post the data to my ASP.NET page. I then pick up the byte array
>> > using
>> > the
>> > request object (XMLData=bytearray..). Can someone point me to an
>> > article
>> > that
>> > shows me how I can do this in ASP.NET, C#?
>> >
>> > Thanks
>> > Danny
>>
>>
>>


Dec 2 '05 #7

P: n/a
My bad, Danny.

That should have read:

byte[] body = encoding.GetBytes("Xml=" + HttpUtility.UrlEncode(XmlString));

I was translating it from some software I've written before, and made a
mistake in the translation.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but you can't make it stink.

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

I tried what you said but get an error saying cannot implicitly convert
type
Byte[] to string,
string body = encoding.GetBytes("Xml=" +
HttpUtility.UrlEncode(XmlString));

I changed it the string body to byte [] and it worked fine when
Xml="sdfdsfsfsd", but when I put a "<" in the xml string an error occurs :
The remote server returned an error: (500) Internal Server Error.

Can you see what could be causing this?

Thanks
Danny

"Kevin Spencer" wrote:
Hi Danny,

If I understand you correctly, they are using a .Net program that employs
the HttpWebRequest to send the XML data via HTTP POST?

If so, you need to create an HTML form on the fly so to speak. This is
not
too hard to do. An HTTP Post is a sequence of "name=value" pairs,
separated
by '&' characters, just like a QueryString, but longer. The "name" part
is
the name of a form field, and the "value" part is the data for that form
field. So, for example, if you wanted to POST a form having one field
named
"foo" and the value in it was "bar" your body would simply look like
this:

foo=bar

Of course, this must all be URLEncoded, and sending an XML document means
a
lot of URLEncoding, for all the tags and such, but using URLEncode() will
do
it. So, to send a single XML document via POST would be something like:

string body = "Xml=" + HttpUtility.URLEncode(XmlString);

"Xml" would be the name of the form field.

It has to be encoded into a byte array because you are actually sending a
stream, but it becomes a string at the other end. So, your code might
look
something like the following:

ASCIIEncoding encoding = new ASCIIEncoding();
Stream requestStream = null;
string lcUrl = "http://localhost/test/receive.aspx";
HttpWebRequest IoHttp = (HttpWebRequest) WebRequest.Create(lcUrl);
IoHttp.Method = "POST";
IoHttp.ContentType = "application/x-www-form-urlencoded";
string body = encoding.GetBytes("Xml=" +
HttpUtility.URLEncode(XmlString));
IoHttp.ContentLength = body.Length;
try
{
requestStream = IoHttp.GetRequestStream();
requestStream.Write(body, 0, body.Length);
}
catch
{
//...
}
finally
{
if (requestStream != null) requestStream.Close();
}

In your ASPX page, you just get Request.Form["Xml"] which is already a
string.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition

"Danny" <Da***@discussions.microsoft.com> wrote in message
news:A5**********************************@microsof t.com...
> Thanks Kevin
>
> To receive the byte array from the client should I be using
> Request.InputStream ?
>
> Assuming the method I think the clients will use to send the data to my
> application, could be like this:
>
> string lcUrl = "http://localhost/test/receive.aspx";
> HttpWebRequest loHttp =
> (HttpWebRequest) WebRequest.Create(lcUrl);
>
> // *** Send any POST data
> string lcPostData =
> "XMLData=" + HttpUtility.UrlEncode("xmldata..");
>
> loHttp.Method="POST";
> byte [] lbPostBuffer =
> System.Text.Encoding.GetEncoding(1252).GetBytes(lc PostData);
> loHttp.ContentLength = lbPostBuffer.Length;
>
>
> "Kevin Spencer" wrote:
>
>> Convert the byte array to a string. Create an XmlDocument instance,
>> and
>> use
>> the Load() method, passing the string to the constructor.
>>
>> --
>> HTH,
>>
>> Kevin Spencer
>> Microsoft MVP
>> ..Net Developer
>> If you push something hard enough,
>> it will fall over.
>> - Fudd's First Law of Opposition
>>
>> "Danny" <Da***@discussions.microsoft.com> wrote in message
>> news:97**********************************@microsof t.com...
>> >I am working on a project where I will receive xml documents from
>> >clients
>> > machines as a byte array. They will use the web browser navigate
>> > method
>> > to
>> > post the data to my ASP.NET page. I then pick up the byte array
>> > using
>> > the
>> > request object (XMLData=bytearray..). Can someone point me to an
>> > article
>> > that
>> > shows me how I can do this in ASP.NET, C#?
>> >
>> > Thanks
>> > Danny
>>
>>
>>


Dec 2 '05 #8

P: n/a
Hi Kevin

When I put "<" character in the xml string the server that receives the xml
returns an error, (500) Internal Server Error.

Can you see what would cause this?

Thanks
Danny

"Kevin Spencer" wrote:
My bad, Danny.

That should have read:

byte[] body = encoding.GetBytes("Xml=" + HttpUtility.UrlEncode(XmlString));

I was translating it from some software I've written before, and made a
mistake in the translation.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but you can't make it stink.

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

I tried what you said but get an error saying cannot implicitly convert
type
Byte[] to string,
string body = encoding.GetBytes("Xml=" +
HttpUtility.UrlEncode(XmlString));

I changed it the string body to byte [] and it worked fine when
Xml="sdfdsfsfsd", but when I put a "<" in the xml string an error occurs :
The remote server returned an error: (500) Internal Server Error.

Can you see what could be causing this?

Thanks
Danny

"Kevin Spencer" wrote:
Hi Danny,

If I understand you correctly, they are using a .Net program that employs
the HttpWebRequest to send the XML data via HTTP POST?

If so, you need to create an HTML form on the fly so to speak. This is
not
too hard to do. An HTTP Post is a sequence of "name=value" pairs,
separated
by '&' characters, just like a QueryString, but longer. The "name" part
is
the name of a form field, and the "value" part is the data for that form
field. So, for example, if you wanted to POST a form having one field
named
"foo" and the value in it was "bar" your body would simply look like
this:

foo=bar

Of course, this must all be URLEncoded, and sending an XML document means
a
lot of URLEncoding, for all the tags and such, but using URLEncode() will
do
it. So, to send a single XML document via POST would be something like:

string body = "Xml=" + HttpUtility.URLEncode(XmlString);

"Xml" would be the name of the form field.

It has to be encoded into a byte array because you are actually sending a
stream, but it becomes a string at the other end. So, your code might
look
something like the following:

ASCIIEncoding encoding = new ASCIIEncoding();
Stream requestStream = null;
string lcUrl = "http://localhost/test/receive.aspx";
HttpWebRequest IoHttp = (HttpWebRequest) WebRequest.Create(lcUrl);
IoHttp.Method = "POST";
IoHttp.ContentType = "application/x-www-form-urlencoded";
string body = encoding.GetBytes("Xml=" +
HttpUtility.URLEncode(XmlString));
IoHttp.ContentLength = body.Length;
try
{
requestStream = IoHttp.GetRequestStream();
requestStream.Write(body, 0, body.Length);
}
catch
{
//...
}
finally
{
if (requestStream != null) requestStream.Close();
}

In your ASPX page, you just get Request.Form["Xml"] which is already a
string.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
If you push something hard enough,
it will fall over.
- Fudd's First Law of Opposition

"Danny" <Da***@discussions.microsoft.com> wrote in message
news:A5**********************************@microsof t.com...
> Thanks Kevin
>
> To receive the byte array from the client should I be using
> Request.InputStream ?
>
> Assuming the method I think the clients will use to send the data to my
> application, could be like this:
>
> string lcUrl = "http://localhost/test/receive.aspx";
> HttpWebRequest loHttp =
> (HttpWebRequest) WebRequest.Create(lcUrl);
>
> // *** Send any POST data
> string lcPostData =
> "XMLData=" + HttpUtility.UrlEncode("xmldata..");
>
> loHttp.Method="POST";
> byte [] lbPostBuffer =
> System.Text.Encoding.GetEncoding(1252).GetBytes(lc PostData);
> loHttp.ContentLength = lbPostBuffer.Length;
>
>
> "Kevin Spencer" wrote:
>
>> Convert the byte array to a string. Create an XmlDocument instance,
>> and
>> use
>> the Load() method, passing the string to the constructor.
>>
>> --
>> HTH,
>>
>> Kevin Spencer
>> Microsoft MVP
>> ..Net Developer
>> If you push something hard enough,
>> it will fall over.
>> - Fudd's First Law of Opposition
>>
>> "Danny" <Da***@discussions.microsoft.com> wrote in message
>> news:97**********************************@microsof t.com...
>> >I am working on a project where I will receive xml documents from
>> >clients
>> > machines as a byte array. They will use the web browser navigate
>> > method
>> > to
>> > post the data to my ASP.NET page. I then pick up the byte array
>> > using
>> > the
>> > request object (XMLData=bytearray..). Can someone point me to an
>> > article
>> > that
>> > shows me how I can do this in ASP.NET, C#?
>> >
>> > Thanks
>> > Danny
>>
>>
>>


Dec 2 '05 #9

P: n/a
I don't really know anything about how you're processing it at the server
end.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but you can't make it stink.

"Danny" <Da***@discussions.microsoft.com> wrote in message
news:3A**********************************@microsof t.com...
Hi Kevin

When I put "<" character in the xml string the server that receives the
xml
returns an error, (500) Internal Server Error.

Can you see what would cause this?

Thanks
Danny

"Kevin Spencer" wrote:
My bad, Danny.

That should have read:

byte[] body = encoding.GetBytes("Xml=" +
HttpUtility.UrlEncode(XmlString));

I was translating it from some software I've written before, and made a
mistake in the translation.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but you can't make it stink.

"Danny" <Da***@discussions.microsoft.com> wrote in message
news:62**********************************@microsof t.com...
> Hi Kevin
>
> I tried what you said but get an error saying cannot implicitly convert
> type
> Byte[] to string,
> string body = encoding.GetBytes("Xml=" +
> HttpUtility.UrlEncode(XmlString));
>
> I changed it the string body to byte [] and it worked fine when
> Xml="sdfdsfsfsd", but when I put a "<" in the xml string an error
> occurs :
> The remote server returned an error: (500) Internal Server Error.
>
> Can you see what could be causing this?
>
> Thanks
> Danny
>
>
>
> "Kevin Spencer" wrote:
>
>> Hi Danny,
>>
>> If I understand you correctly, they are using a .Net program that
>> employs
>> the HttpWebRequest to send the XML data via HTTP POST?
>>
>> If so, you need to create an HTML form on the fly so to speak. This is
>> not
>> too hard to do. An HTTP Post is a sequence of "name=value" pairs,
>> separated
>> by '&' characters, just like a QueryString, but longer. The "name"
>> part
>> is
>> the name of a form field, and the "value" part is the data for that
>> form
>> field. So, for example, if you wanted to POST a form having one field
>> named
>> "foo" and the value in it was "bar" your body would simply look like
>> this:
>>
>> foo=bar
>>
>> Of course, this must all be URLEncoded, and sending an XML document
>> means
>> a
>> lot of URLEncoding, for all the tags and such, but using URLEncode()
>> will
>> do
>> it. So, to send a single XML document via POST would be something
>> like:
>>
>> string body = "Xml=" + HttpUtility.URLEncode(XmlString);
>>
>> "Xml" would be the name of the form field.
>>
>> It has to be encoded into a byte array because you are actually
>> sending a
>> stream, but it becomes a string at the other end. So, your code might
>> look
>> something like the following:
>>
>> ASCIIEncoding encoding = new ASCIIEncoding();
>> Stream requestStream = null;
>> string lcUrl = "http://localhost/test/receive.aspx";
>> HttpWebRequest IoHttp = (HttpWebRequest) WebRequest.Create(lcUrl);
>> IoHttp.Method = "POST";
>> IoHttp.ContentType = "application/x-www-form-urlencoded";
>> string body = encoding.GetBytes("Xml=" +
>> HttpUtility.URLEncode(XmlString));
>> IoHttp.ContentLength = body.Length;
>> try
>> {
>> requestStream = IoHttp.GetRequestStream();
>> requestStream.Write(body, 0, body.Length);
>> }
>> catch
>> {
>> //...
>> }
>> finally
>> {
>> if (requestStream != null) requestStream.Close();
>> }
>>
>> In your ASPX page, you just get Request.Form["Xml"] which is already a
>> string.
>>
>> --
>> HTH,
>>
>> Kevin Spencer
>> Microsoft MVP
>> ..Net Developer
>> If you push something hard enough,
>> it will fall over.
>> - Fudd's First Law of Opposition
>>
>> "Danny" <Da***@discussions.microsoft.com> wrote in message
>> news:A5**********************************@microsof t.com...
>> > Thanks Kevin
>> >
>> > To receive the byte array from the client should I be using
>> > Request.InputStream ?
>> >
>> > Assuming the method I think the clients will use to send the data to
>> > my
>> > application, could be like this:
>> >
>> > string lcUrl = "http://localhost/test/receive.aspx";
>> > HttpWebRequest loHttp =
>> > (HttpWebRequest) WebRequest.Create(lcUrl);
>> >
>> > // *** Send any POST data
>> > string lcPostData =
>> > "XMLData=" + HttpUtility.UrlEncode("xmldata..");
>> >
>> > loHttp.Method="POST";
>> > byte [] lbPostBuffer =
>> > System.Text.Encoding.GetEncoding(1252).GetBytes(lc PostData);
>> > loHttp.ContentLength = lbPostBuffer.Length;
>> >
>> >
>> > "Kevin Spencer" wrote:
>> >
>> >> Convert the byte array to a string. Create an XmlDocument instance,
>> >> and
>> >> use
>> >> the Load() method, passing the string to the constructor.
>> >>
>> >> --
>> >> HTH,
>> >>
>> >> Kevin Spencer
>> >> Microsoft MVP
>> >> ..Net Developer
>> >> If you push something hard enough,
>> >> it will fall over.
>> >> - Fudd's First Law of Opposition
>> >>
>> >> "Danny" <Da***@discussions.microsoft.com> wrote in message
>> >> news:97**********************************@microsof t.com...
>> >> >I am working on a project where I will receive xml documents from
>> >> >clients
>> >> > machines as a byte array. They will use the web browser navigate
>> >> > method
>> >> > to
>> >> > post the data to my ASP.NET page. I then pick up the byte array
>> >> > using
>> >> > the
>> >> > request object (XMLData=bytearray..). Can someone point me to an
>> >> > article
>> >> > that
>> >> > shows me how I can do this in ASP.NET, C#?
>> >> >
>> >> > Thanks
>> >> > Danny
>> >>
>> >>
>> >>
>>
>>
>>


Dec 2 '05 #10

P: n/a
Basically I have an ASP.NET page, in the PAGE_LOAD event I have:
//Response.Write (Request.Form["XMLData"]);
I would assume this would be returned to the client application.

Thanks
Danny

"Kevin Spencer" wrote:
I don't really know anything about how you're processing it at the server
end.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but you can't make it stink.

"Danny" <Da***@discussions.microsoft.com> wrote in message
news:3A**********************************@microsof t.com...
Hi Kevin

When I put "<" character in the xml string the server that receives the
xml
returns an error, (500) Internal Server Error.

Can you see what would cause this?

Thanks
Danny

"Kevin Spencer" wrote:
My bad, Danny.

That should have read:

byte[] body = encoding.GetBytes("Xml=" +
HttpUtility.UrlEncode(XmlString));

I was translating it from some software I've written before, and made a
mistake in the translation.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but you can't make it stink.

"Danny" <Da***@discussions.microsoft.com> wrote in message
news:62**********************************@microsof t.com...
> Hi Kevin
>
> I tried what you said but get an error saying cannot implicitly convert
> type
> Byte[] to string,
> string body = encoding.GetBytes("Xml=" +
> HttpUtility.UrlEncode(XmlString));
>
> I changed it the string body to byte [] and it worked fine when
> Xml="sdfdsfsfsd", but when I put a "<" in the xml string an error
> occurs :
> The remote server returned an error: (500) Internal Server Error.
>
> Can you see what could be causing this?
>
> Thanks
> Danny
>
>
>
> "Kevin Spencer" wrote:
>
>> Hi Danny,
>>
>> If I understand you correctly, they are using a .Net program that
>> employs
>> the HttpWebRequest to send the XML data via HTTP POST?
>>
>> If so, you need to create an HTML form on the fly so to speak. This is
>> not
>> too hard to do. An HTTP Post is a sequence of "name=value" pairs,
>> separated
>> by '&' characters, just like a QueryString, but longer. The "name"
>> part
>> is
>> the name of a form field, and the "value" part is the data for that
>> form
>> field. So, for example, if you wanted to POST a form having one field
>> named
>> "foo" and the value in it was "bar" your body would simply look like
>> this:
>>
>> foo=bar
>>
>> Of course, this must all be URLEncoded, and sending an XML document
>> means
>> a
>> lot of URLEncoding, for all the tags and such, but using URLEncode()
>> will
>> do
>> it. So, to send a single XML document via POST would be something
>> like:
>>
>> string body = "Xml=" + HttpUtility.URLEncode(XmlString);
>>
>> "Xml" would be the name of the form field.
>>
>> It has to be encoded into a byte array because you are actually
>> sending a
>> stream, but it becomes a string at the other end. So, your code might
>> look
>> something like the following:
>>
>> ASCIIEncoding encoding = new ASCIIEncoding();
>> Stream requestStream = null;
>> string lcUrl = "http://localhost/test/receive.aspx";
>> HttpWebRequest IoHttp = (HttpWebRequest) WebRequest.Create(lcUrl);
>> IoHttp.Method = "POST";
>> IoHttp.ContentType = "application/x-www-form-urlencoded";
>> string body = encoding.GetBytes("Xml=" +
>> HttpUtility.URLEncode(XmlString));
>> IoHttp.ContentLength = body.Length;
>> try
>> {
>> requestStream = IoHttp.GetRequestStream();
>> requestStream.Write(body, 0, body.Length);
>> }
>> catch
>> {
>> //...
>> }
>> finally
>> {
>> if (requestStream != null) requestStream.Close();
>> }
>>
>> In your ASPX page, you just get Request.Form["Xml"] which is already a
>> string.
>>
>> --
>> HTH,
>>
>> Kevin Spencer
>> Microsoft MVP
>> ..Net Developer
>> If you push something hard enough,
>> it will fall over.
>> - Fudd's First Law of Opposition
>>
>> "Danny" <Da***@discussions.microsoft.com> wrote in message
>> news:A5**********************************@microsof t.com...
>> > Thanks Kevin
>> >
>> > To receive the byte array from the client should I be using
>> > Request.InputStream ?
>> >
>> > Assuming the method I think the clients will use to send the data to
>> > my
>> > application, could be like this:
>> >
>> > string lcUrl = "http://localhost/test/receive.aspx";
>> > HttpWebRequest loHttp =
>> > (HttpWebRequest) WebRequest.Create(lcUrl);
>> >
>> > // *** Send any POST data
>> > string lcPostData =
>> > "XMLData=" + HttpUtility.UrlEncode("xmldata..");
>> >
>> > loHttp.Method="POST";
>> > byte [] lbPostBuffer =
>> > System.Text.Encoding.GetEncoding(1252).GetBytes(lc PostData);
>> > loHttp.ContentLength = lbPostBuffer.Length;
>> >
>> >
>> > "Kevin Spencer" wrote:
>> >
>> >> Convert the byte array to a string. Create an XmlDocument instance,
>> >> and
>> >> use
>> >> the Load() method, passing the string to the constructor.
>> >>
>> >> --
>> >> HTH,
>> >>
>> >> Kevin Spencer
>> >> Microsoft MVP
>> >> ..Net Developer
>> >> If you push something hard enough,
>> >> it will fall over.
>> >> - Fudd's First Law of Opposition
>> >>
>> >> "Danny" <Da***@discussions.microsoft.com> wrote in message
>> >> news:97**********************************@microsof t.com...
>> >> >I am working on a project where I will receive xml documents from
>> >> >clients
>> >> > machines as a byte array. They will use the web browser navigate
>> >> > method
>> >> > to
>> >> > post the data to my ASP.NET page. I then pick up the byte array
>> >> > using
>> >> > the
>> >> > request object (XMLData=bytearray..). Can someone point me to an
>> >> > article
>> >> > that
>> >> > shows me how I can do this in ASP.NET, C#?
>> >> >
>> >> > Thanks
>> >> > Danny
>> >>
>> >>
>> >>
>>
>>
>>


Dec 3 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.