473,698 Members | 2,145 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 3003
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
12758
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
3054
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
35769
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
13003
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
5011
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
3195
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
3111
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
1977
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
2801
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
2353
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
8608
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
9164
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...
0
9029
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7734
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6524
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
4370
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
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3051
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2332
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.