473,383 Members | 1,892 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,383 software developers and data experts.

StreamReader

I am receiving xml via tcp/ip and want to save it into a msmq queue.
when I use the StreamReader.ReadLine() it only reads one line of the
stream. but my xml could be more than 1 line.
when I use StreamReader.ReadToEnd() it just listens to the port until the
connection is closed and then it writes it to the queue, which is not the
method that i want because more than one xml are saved to a queue at a time.
basicly i need a read method that receives 1 xml that comes through and
saves it to the queue.

thanks in advance
Nov 18 '05 #1
4 2978
How are you constructing your StreamReader?
Are you using a WebResponse object?

In my code, I create a WebResponse object from a WebRequest object, I then
create my stream as follows

Stream oStream = oWebResponse.GetResponseStream();
Encoding oEncoding = System.Text.Encoding.GetEncoding("utf=8");
StreamReader oStreamReader = new StreamReader(oStream, oEncoding);
string sXmlData = oStreamReader.ReadToEnd();
<jo*****@hotmail.com> wrote in message
news:eT**************@TK2MSFTNGP12.phx.gbl...
I am receiving xml via tcp/ip and want to save it into a msmq queue.
when I use the StreamReader.ReadLine() it only reads one line of the
stream. but my xml could be more than 1 line.
when I use StreamReader.ReadToEnd() it just listens to the port until the
connection is closed and then it writes it to the queue, which is not the
method that i want because more than one xml are saved to a queue at a time. basicly i need a read method that receives 1 xml that comes through and
saves it to the queue.

thanks in advance

Nov 18 '05 #2
I had to use something like this once:

string thisline = "";
while(StreamReader.Peek() != null)
{
thisline += StreamReader.ReadLine();
if(thisline.IndexOf("</XMLROOTELEMENT>")!=-1)
{
sendToQue(thisline);
thisline = "";
}
}
Nov 18 '05 #3
I am trying to use your code but i get an error on oWebresponse: use of
unassigned local variable:

WebResponse oWebResponse;

Stream ostream= oWebResponse.GetResponseStream();
StreamReader oStreamReader= new StreamReader(ostream);
string strXMLData=oStreamReader.ReadToEnd();

Thanks


"George Durzi" <gd****@hotmail.com> wrote in message
news:eE**************@TK2MSFTNGP10.phx.gbl...
How are you constructing your StreamReader?
Are you using a WebResponse object?

In my code, I create a WebResponse object from a WebRequest object, I then
create my stream as follows

Stream oStream = oWebResponse.GetResponseStream();
Encoding oEncoding = System.Text.Encoding.GetEncoding("utf=8");
StreamReader oStreamReader = new StreamReader(oStream, oEncoding);
string sXmlData = oStreamReader.ReadToEnd();
<jo*****@hotmail.com> wrote in message
news:eT**************@TK2MSFTNGP12.phx.gbl...
I am receiving xml via tcp/ip and want to save it into a msmq queue.
when I use the StreamReader.ReadLine() it only reads one line of the
stream. but my xml could be more than 1 line.
when I use StreamReader.ReadToEnd() it just listens to the port until the connection is closed and then it writes it to the queue, which is not the method that i want because more than one xml are saved to a queue at a

time.
basicly i need a read method that receives 1 xml that comes through and
saves it to the queue.

thanks in advance


Nov 18 '05 #4
I didn't include that code coz I didn't think the content of the WebResponse
was relevant. I don't think it's applicable to what you're doing, but here
you go

StringBuilder sbPayload = new StringBuilder();

sbPayload.Append("<?xml version=\"1.0\"?>");

sbPayload.Append("<a:searchrequest xmlns:a=\"DAV:\">");

sbPayload.Append("<sql> SELECT \"urn:schemas:contacts:fileas\" ");

sbPayload.Append(", \"urn:schemas:contacts:givenName\" ");

sbPayload.Append(", \"urn:schemas:contacts:sn\" ");

sbPayload.Append(", \"urn:schemas:contacts:o\" ");

sbPayload.Append("FROM Scope('SHALLOW TRAVERSAL OF \"\"') ");

sbPayload.Append("Where \"DAV:isfolder\" = false AND \"DAV:contentclass\"
");

sbPayload.Append("= 'urn:content-classes:person'");

sbPayload.Append(" ORDER BY \"urn:schemas:contacts:fileas\" ASC");

sbPayload.Append("</>");

sbPayload.Append("</>");

// Array to hold Xml Payload

byte[] arPayload = null;

try

{

// Get Payload and Encode it to utf-8

arPayload = Encoding.UTF8.GetBytes((string)sbPayload.ToString( ));

// Create HTTP Web Request & Set Properties

HttpWebRequest oWebRequest =
(System.Net.HttpWebRequest)HttpWebRequest.Create(s SourceURL);

oWebRequest.Method = "SEARCH";

oWebRequest.ContentType = "text/xml";

oWebRequest.ContentLength = arPayload.Length;

// Inject the Search Payload into the RequestStream

Stream oRequestStream = oWebRequest.GetRequestStream();

oRequestStream.Write(arPayload, 0, arPayload.Length);

oRequestStream.Close();
// Set Credentials to Access Exchange Store

oWebRequest.Credentials = CreateCredentialCache(sSourceURL);

// Create the Web Response Object

System.Net.WebResponse oWebResponse = (System.Net.WebResponse)
oWebRequest.GetResponse();

// Get the Xml Response Stream
<jo*****@hotmail.com> wrote in message
news:OX*************@TK2MSFTNGP09.phx.gbl...
I am trying to use your code but i get an error on oWebresponse: use of
unassigned local variable:

WebResponse oWebResponse;

Stream ostream= oWebResponse.GetResponseStream();
StreamReader oStreamReader= new StreamReader(ostream);
string strXMLData=oStreamReader.ReadToEnd();

Thanks


"George Durzi" <gd****@hotmail.com> wrote in message
news:eE**************@TK2MSFTNGP10.phx.gbl...
How are you constructing your StreamReader?
Are you using a WebResponse object?

In my code, I create a WebResponse object from a WebRequest object, I then
create my stream as follows

Stream oStream = oWebResponse.GetResponseStream();
Encoding oEncoding = System.Text.Encoding.GetEncoding("utf=8");
StreamReader oStreamReader = new StreamReader(oStream, oEncoding);
string sXmlData = oStreamReader.ReadToEnd();
<jo*****@hotmail.com> wrote in message
news:eT**************@TK2MSFTNGP12.phx.gbl...
I am receiving xml via tcp/ip and want to save it into a msmq queue.
when I use the StreamReader.ReadLine() it only reads one line of the
stream. but my xml could be more than 1 line.
when I use StreamReader.ReadToEnd() it just listens to the port until

the connection is closed and then it writes it to the queue, which is not the method that i want because more than one xml are saved to a queue at a

time.
basicly i need a read method that receives 1 xml that comes through and saves it to the queue.

thanks in advance



Nov 18 '05 #5

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

Similar topics

9
by: oafyuf | last post by:
Hi, I'm having performanbce issues with StreamReader and was wondering what I could do to improve it... The following takes around 3 seconds to process! The content of the response is: ...
5
by: Anders Olsson | last post by:
I need to create a StreamReader which starts from the position of an existing StreamReader. This way, the second StreamReader can read lines "ahead" in an own loop, and then I can go back to the...
11
by: Tiger | last post by:
We can use seek() in the FileStream class,as we know. But I found that seek() is not work correctly in StreamReader. Who can tell me how to use seek() correctly in StreamReader? thanks a lot! I...
2
by: Keith Kingsley | last post by:
I'm using a StreamReader to read in several lines from an ASCII file. I'd like to know the StreamReader's "true" position-- that is, the number of bytes into the file that the StreamReader has...
3
by: Arno | last post by:
Hi, I'm using TcpClient for communication between two PC running a small piece of software. The protocol used has been designed internally and is HTTP similar (command line, headers, body). A...
3
by: Mika M | last post by:
Hello! I'm reading text file line by line using the StreamReader like code below shows. Reading is working fine, but if readed line contains Scandinavian letters like äÄöÖ then those letters are...
3
by: Arpan | last post by:
A file can be read using only the StreamReader object like this: Dim sReader As StreamReader sReader = New StreamReader(Server.MapPath("File1.txt")) While(sReader.Peek -1)...
1
by: garyusenet | last post by:
>From MSDN I'm trying to learn more about streamreader. I'm working my way down the MSDN definition. The first entry is the Public Constructor StreamReader. I'm fairly happy I have a basic grasp on...
1
by: Sladan | last post by:
Im trying to read a xml-file with a StreamReader. For the moment I'm using the following code. streamReader = new StreamReader(stream, System.Text.Encoding.Default); string feedData =...
0
by: rajana | last post by:
Dear All, We have Ansi file with german characters (Ä / Ø) , We are using Streamreader to read the contents of the file. But Readline() not able to read the German characters. We tried all...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.