473,804 Members | 2,205 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

StreamReader

I am receiving xml via tcp/ip and want to save it into a msmq queue.
when I use the StreamReader.Re adLine() it only reads one line of the
stream. but my xml could be more than 1 line.
when I use StreamReader.Re adToEnd() 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 3020
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.Ge tResponseStream ();
Encoding oEncoding = System.Text.Enc oding.GetEncodi ng("utf=8");
StreamReader oStreamReader = new StreamReader(oS tream, oEncoding);
string sXmlData = oStreamReader.R eadToEnd();
<jo*****@hotmai l.com> wrote in message
news:eT******** ******@TK2MSFTN GP12.phx.gbl...
I am receiving xml via tcp/ip and want to save it into a msmq queue.
when I use the StreamReader.Re adLine() it only reads one line of the
stream. but my xml could be more than 1 line.
when I use StreamReader.Re adToEnd() 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(StreamRea der.Peek() != null)
{
thisline += StreamReader.Re adLine();
if(thisline.Ind exOf("</XMLROOTELEMENT> ")!=-1)
{
sendToQue(thisl ine);
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.Ge tResponseStream ();
StreamReader oStreamReader= new StreamReader(os tream);
string strXMLData=oStr eamReader.ReadT oEnd();

Thanks


"George Durzi" <gd****@hotmail .com> wrote in message
news:eE******** ******@TK2MSFTN GP10.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.Ge tResponseStream ();
Encoding oEncoding = System.Text.Enc oding.GetEncodi ng("utf=8");
StreamReader oStreamReader = new StreamReader(oS tream, oEncoding);
string sXmlData = oStreamReader.R eadToEnd();
<jo*****@hotmai l.com> wrote in message
news:eT******** ******@TK2MSFTN GP12.phx.gbl...
I am receiving xml via tcp/ip and want to save it into a msmq queue.
when I use the StreamReader.Re adLine() it only reads one line of the
stream. but my xml could be more than 1 line.
when I use StreamReader.Re adToEnd() 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.Appen d("<?xml version=\"1.0\" ?>");

sbPayload.Appen d("<a:searchreq uest xmlns:a=\"DAV:\ ">");

sbPayload.Appen d("<sql> SELECT \"urn:schemas:c ontacts:fileas\ " ");

sbPayload.Appen d(", \"urn:schemas:c ontacts:givenNa me\" ");

sbPayload.Appen d(", \"urn:schemas:c ontacts:sn\" ");

sbPayload.Appen d(", \"urn:schemas:c ontacts:o\" ");

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

sbPayload.Appen d("Where \"DAV:isfolder\ " = false AND \"DAV:contentcl ass\"
");

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

sbPayload.Appen d(" ORDER BY \"urn:schemas:c ontacts:fileas\ " ASC");

sbPayload.Appen d("</>");

sbPayload.Appen d("</>");

// Array to hold Xml Payload

byte[] arPayload = null;

try

{

// Get Payload and Encode it to utf-8

arPayload = Encoding.UTF8.G etBytes((string )sbPayload.ToSt ring());

// Create HTTP Web Request & Set Properties

HttpWebRequest oWebRequest =
(System.Net.Htt pWebRequest)Htt pWebRequest.Cre ate(sSourceURL) ;

oWebRequest.Met hod = "SEARCH";

oWebRequest.Con tentType = "text/xml";

oWebRequest.Con tentLength = arPayload.Lengt h;

// Inject the Search Payload into the RequestStream

Stream oRequestStream = oWebRequest.Get RequestStream() ;

oRequestStream. Write(arPayload , 0, arPayload.Lengt h);

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

oWebRequest.Cre dentials = CreateCredentia lCache(sSourceU RL);

// Create the Web Response Object

System.Net.WebR esponse oWebResponse = (System.Net.Web Response)
oWebRequest.Get Response();

// Get the Xml Response Stream
<jo*****@hotmai l.com> wrote in message
news:OX******** *****@TK2MSFTNG P09.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.Ge tResponseStream ();
StreamReader oStreamReader= new StreamReader(os tream);
string strXMLData=oStr eamReader.ReadT oEnd();

Thanks


"George Durzi" <gd****@hotmail .com> wrote in message
news:eE******** ******@TK2MSFTN GP10.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.Ge tResponseStream ();
Encoding oEncoding = System.Text.Enc oding.GetEncodi ng("utf=8");
StreamReader oStreamReader = new StreamReader(oS tream, oEncoding);
string sXmlData = oStreamReader.R eadToEnd();
<jo*****@hotmai l.com> wrote in message
news:eT******** ******@TK2MSFTN GP12.phx.gbl...
I am receiving xml via tcp/ip and want to save it into a msmq queue.
when I use the StreamReader.Re adLine() it only reads one line of the
stream. but my xml could be more than 1 line.
when I use StreamReader.Re adToEnd() 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
12777
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: "<?xml version="1.0" ?><ERROR>ORA-01403: no data found</ERROR>" HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strURIQuery);
5
3072
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 outer loop and the first StreamReader is still where I left it. I have been trying to do this using this code: StreamReader sr2 = sr1 //Where sr1 is the existing StreamReader This seems to work just fine, so I guess this is a supported way...
11
35809
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 use the seek() like this: StreamReader r; ....... r.BaseStream.seek(.....);
2
13006
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 read. I thought about using MyStreamReader.BaseStream.Position, but this always seems to return a multiple of the StreamReader's buffer size (which seems natural-- as I understand it the StreamReader reads from the underlying stream in discrete...
3
5023
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 typical response in this protocol would be:
3
3198
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 simply cut off ! Why ??? For example my lastname Mähönen will be Mhnen. How should I change code to get all letters as is of the file? Dim strLine as String Dim sr As StreamReader = New StreamReader(strFilePath)
3
3114
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) Response.Write(sReader.ReadLine) End While as well as using the FileStream object along with the StreamReader object like this:
1
1986
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 this. It is the part of the Streamreader class that creates a StreamReader instance for a given Stream. The next entry however I don't understand: - Public Fields Name Description Null A StreamReader object around an empty stream.
1
2891
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 = streamReader.ReadToEnd(); I'm using System.Text.Encoding.Default so that I can get some swedish characters working. But I'm having problem when reading a xml-file that's encoded with UTF-8. In the beginning of the xml-files you have the encoding for the...
0
2365
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 possibilities of calling the streamreader, but nothing worked. Dim sr As StreamReader = New StreamReader(Filename, System.Text.Encoding.Default, True) Dim sr As StreamReader = New StreamReader(Filename, _System.Text.Encoding.ASCII, False, 512)
0
9715
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9595
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10600
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10354
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7642
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6867
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5535
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.