Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Pass stream reader as paramaeter to webmethod asp.net vb.net

Posted on 2007-12-06
8
Medium Priority
?
1,742 Views
Last Modified: 2013-11-07
Hi all,

I have a web method that accepts a streamreader as parameter.I am trying to call that webmethod from webpage and pass astreamreader which reads an xml file to that webmethod.

But i am getting an error like value of type system.io.streamreader cannot be converted to type localhost.streamreader.

My requirement is client will send an xml file to my server application.I am reading that request using streamreader from a webpage in my server app.Then i am calling a webmethod which accepts parameter as stream reader to parse that xml file inside webmethod .

how can i send streamreader as parameter to that webmethod.

Open in new window

0
Comment
Question by:aditya_raj
  • 4
  • 4
8 Comments
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 20424675
You can't use a StreamReader as a parameter in a web method. It contains a live connection to the file that you are reading, and that can not be serialised into a string value to put in the SOAP message.

You have to send the data in a way that can be represented as a string, so just read the stream into a string, and send the string value to the web service.
0
 

Author Comment

by:aditya_raj
ID: 20424728
OK.
I am not saving the xml file which i got from client.I am reading that request using

 Dim requestStream As Stream = Request.InputStream
 Dim rdr As StreamReader = New StreamReader(requestStream)

Can you please tell me without saving the file how can i make an xmlstring and pass it to webmethod.
0
 
LVL 29

Accepted Solution

by:
Göran Andersson earned 2000 total points
ID: 20424806
Like this:

Dim xml As String = rdr.ReadToEnd()

Also, you might need to specify the encoding from the request when you create the stream reader, to get it to read the stream correctly:

Dim rdr As StreamReader = New StreamReader(requestStream, Request.RequestEncoding)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:aditya_raj
ID: 20424830
<?xml version="1.0" standalone="yes"?>
 <Details>
            <UserName>piscesIt</UserName>
            <Password>hello</Password>
            <CustomerNumber>7323</CustomerNumber>
            <NodeAccountCode>Pisces15</NodeAccountCode>
            <AccountPassword>hello</AccountPassword>
</Details>
Dim requestStream As Stream = Request.InputStream
 Dim rdr As StreamReader = New StreamReader(requestStream)
Dim requeststring As String = rdr.ReadToEnd()
I tried like that.
But i am getting Root element is missing error.
0
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 20424853
That code only treats the data as a string, not an xml document, so it can't produce that error message.

What does the code look like where the error occurs?
0
 

Author Comment

by:aditya_raj
ID: 20424875
Actually i want that reader to read using dataset and also need to convert xmlstring.But it is allowing to do only one function.

I will give my code.

Dim Requestds As New DataSet
        'reading the request object from client using the dataset
        Dim requestStream As Stream = Request.InputStream
        Dim rdr1 As StreamReader = New StreamReader(requestStream)
        Dim rdr2 As StreamReader = New StreamReader(requestStream)
        Dim xmlstring As String = rdr1.ReadToEnd
        Requestds.ReadXml(rdr2)

if i do like this it is going with no error.

But i can read the request stream only once.
0
 

Author Comment

by:aditya_raj
ID: 20424904
please read the above comment too.
Can't i do more that one operation using that streamreader.
If i do rdr.readtoend  first i am getting succesful.an then do dataset.readxml(rdr) i am getting root element missing.

In the same way,if i do dataset.readxml(rdr) first it is successful.Then on doing  rdr.readtoend is giving root element missing error


0
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 20425799
First get the data into the string, then you can create a StringReader to read the string as a stream:

Dim xml As String = rdr.ReadToEnd()
rdr.Close()
Dim reader As New StringReader(xml)
dataset.ReadXml(reader)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question