473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

byte array problem

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
10 2650
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
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Steve Mauldin | last post by:
I came across an example in the MSDN documentation using RC2 encryption(the link to the article is at the end of this message). When I tried it I had a problem with getting back the same length...
13
by: Bryan Parkoff | last post by:
I have two variables: "char A" and "short B". I can be able to convert from A to B using explicit case conversion with no problem like "B = short (A);". Right now, I have two variables: "char T"...
13
by: Ray Z | last post by:
So far, I get the idea that if I want to use both the unmanaged and managed memory, I can not avoid memory copy. But I DO need to avoid it. I get a idea that maybe I could use "union" to convert...
6
by: Ricardo Quintanilla | last post by:
i have a code that sends data to a socket listening over as400 platform, the socket responds to me as a "byte array". then i need to convert the "byte array" into a string. the problem is that...
15
by: Kueishiong Tu | last post by:
How do I convert a Byte array (unsigned char managed) to a char array(unmanaged) with wide character taken into account?
8
by: intrepid_dw | last post by:
Hello, all. I've created a C# dll that contains, among other things, two functions dealing with byte arrays. The first is a function that returns a byte array, and the other is intended to...
32
by: Guoqi Zheng | last post by:
I am really do not know so much about byte/bit, etc. Question, if I defined a byte(), how can I add a single byte to it? what I want is that I have an array of bytes, I loop that array, look at...
3
by: jackmejia | last post by:
Hello I am fighting to sync a C++ client with a C# server, I have managed to create a byte array in C++ stored as char* to be sent over the network to the server written in C#. on the C# side,...
1
by: MimiMi | last post by:
I'm trying to decrypt a byte array in java that was encrypted in C#. I don't get any error messages, just a result that's completely not what I was hoping for. I think I am using the same type of...
2
by: MimiMi | last post by:
I'm trying to decrypt a byte array in java that was encrypted in C#. I don't get any error messages, just a result that's completely not what I was hoping for. I think I am using the same type of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.