473,388 Members | 1,340 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,388 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 2979
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: 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:
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...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.