no accessible 'GetBytes' can be called with these arguments

L

les

I'm trying to http post xml data to a remote server and I get this
error:

BC30518: Overload resolution failed because no accessible 'GetBytes'
can be called with these arguments:

Line 20: Dim d As Byte() =
System.Text.Encoding.ASCII.GetBytes(readStream)

The aspx page is shown below. Can anyone help?
Thanks
Leslie

<%@ Page Language="VB" debug="True"%>
<%@ import namespace="system.io"%>
<%@ Import Namespace="System.Text" %>
<%@ import namespace="system.xml"%>
<%@ import Namespace="System.Net" %>
<%@ import Namespace="System.Web" %>
<Script Language="vb" runat="server">
Sub Page_Load(s as object, e as eventargs)

'Creates a streamreader from an xml file
Dim HttpWReq As HttpWebRequest =
CType(WebRequest.Create("http://server/datafile.xml"), HttpWebRequest)
Dim HttpWResp As HttpWebResponse = CType(HttpWReq.GetResponse(),
HttpWebResponse)
Dim receiveStream As Stream = HttpWResp.GetResponseStream()
Dim encode As Encoding =
system.Text.Encoding.GetEncoding("ISO-8859-1")
Dim readStream As New StreamReader(receiveStream, encode)

'post readstream to target server
Dim web As New System.Net.WebClient()
web.Headers.Add("Content-Type", "text/xml")
Dim d As Byte() = System.Text.Encoding.ASCII.GetBytes(readStream)
Dim res As Byte() = web.UploadData("http://targetserver/postpage",
"POST", d)
Console.Write(System.Text.Encoding.ASCII.GetString(res))
response.write (System.Text.Encoding.ASCII.GetString(res))

readStream.Close()
HttpWResp.Close()

End Sub
</script>
 
L

les

Thanks Armin, but I'm a bit lost here. How would I change my code to
pass a string or array of chars?

Thanks
Leslie


Right, you can not pass a stream to the GetBytes method. Pass a String or an
array of Chars.



<%@ Page Language="VB" debug="True"%>
<%@ import namespace="system.io"%>
<%@ Import Namespace="System.Text" %>
<%@ import namespace="system.xml"%>
<%@ import Namespace="System.Net" %>
<%@ import Namespace="System.Web" %>
<Script Language="vb" runat="server">
Sub Page_Load(s as object, e as eventargs)

'Creates a streamreader from an xml file
Dim HttpWReq As HttpWebRequest =
CType(WebRequest.Create("http://server/datafile.xml"), HttpWebRequest)
Dim HttpWResp As HttpWebResponse = CType(HttpWReq.GetResponse(),
HttpWebResponse)
Dim receiveStream As Stream = HttpWResp.GetResponseStream()
Dim encode As Encoding =
system.Text.Encoding.GetEncoding("ISO-8859-1")
Dim readStream As New StreamReader(receiveStream, encode)

'post readstream to target server
Dim web As New System.Net.WebClient()
web.Headers.Add("Content-Type", "text/xml")
Dim d As Byte() = System.Text.Encoding.ASCII.GetBytes(readStream)
Dim res As Byte() = web.UploadData("http://targetserver/postpage",
"POST", d)
Console.Write(System.Text.Encoding.ASCII.GetString(res))
response.write (System.Text.Encoding.ASCII.GetString(res))

readStream.Close()
HttpWResp.Close()

End Sub
</script>
 
A

Armin Zingler

L

les

I'm creating the streamreader ok , but can't work out how to do the
rest. This bit encodes the stream as iso-8859-1, but how do I convert
this to a string?

system.Text.Encoding.GetEncoding("ISO-8859-1")
Dim readStream As New StreamReader(receiveStream, encode)


When you create the Streamreader, you can pass an Encoding object that
specifies the encoding of the chars in the stream. After reading a string
from the Stream, you can pass it to the GetBytes method of an Encoding
object to get the encoded byte array.



<Script Language="vb" runat="server">
Sub Page_Load(s as object, e as eventargs)

'Creates a streamreader from an xml file
Dim HttpWReq As HttpWebRequest =
CType(WebRequest.Create("http://server/datafile.xml"), HttpWebRequest)
Dim HttpWResp As HttpWebResponse = CType(HttpWReq.GetResponse(),
HttpWebResponse)
Dim receiveStream As Stream = HttpWResp.GetResponseStream()
Dim encode As Encoding =
system.Text.Encoding.GetEncoding("ISO-8859-1")
Dim readStream As New StreamReader(receiveStream, encode)

'post readstream to target server
Dim web As New System.Net.WebClient()
web.Headers.Add("Content-Type", "text/xml")
Dim d As Byte() = System.Text.Encoding.ASCII.GetBytes(readStream)
Dim res As Byte() = web.UploadData("http://targetserver/postpage",
"POST", d)
Console.Write(System.Text.Encoding.ASCII.GetString(res))
response.write (System.Text.Encoding.ASCII.GetString(res))

readStream.Close()
HttpWResp.Close()

End Sub
</script>
 
A

Armin Zingler

I'm creating the streamreader ok , but can't work out how to do
the rest. This bit encodes the stream as iso-8859-1, but how do I
convert this to a string?

system.Text.Encoding.GetEncoding("ISO-8859-1")
Dim readStream As New StreamReader(receiveStream, encode)

What do you want to convert to a string? If the text in the stream is
encoded in "ISO-8859-1", you can now use the stream to read from
(readStream.readline or readStream.readtoend).

Later you can convert the string to a byte array by passing it to the
GetBytes method of an Encoding object.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
L

les

Now I'm really confused....I thought you were telling me I need to
convert the streamreader to a string before it can be passed to the
getbytes method.

Is it possible you could show me how to modify the code? I'm quite
lost here
Thanks
Leslie


What do you want to convert to a string? If the text in the stream is
encoded in "ISO-8859-1", you can now use the stream to read from
(readStream.readline or readStream.readtoend).

Later you can convert the string to a byte array by passing it to the
GetBytes method of an Encoding object.


<Script Language="vb" runat="server">
Sub Page_Load(s as object, e as eventargs)
'Creates a streamreader from an xml file
Dim HttpWReq As HttpWebRequest =
CType(WebRequest.Create("http://server/datafile.xml"), HttpWebRequest)
Dim HttpWResp As HttpWebResponse = CType(HttpWReq.GetResponse(),
HttpWebResponse)
Dim receiveStream As Stream = HttpWResp.GetResponseStream()
Dim encode As Encoding =
system.Text.Encoding.GetEncoding("ISO-8859-1")
Dim readStream As New StreamReader(receiveStream, encode)

'post readstream to target server
Dim web As New System.Net.WebClient()
web.Headers.Add("Content-Type", "text/xml")
Dim d As Byte() = System.Text.Encoding.ASCII.GetBytes(readStream)
Dim res As Byte() = web.UploadData("http://targetserver/postpage",
"POST", d)
Console.Write(System.Text.Encoding.ASCII.GetString(res))
response.write (System.Text.Encoding.ASCII.GetString(res))

readStream.Close()
HttpWResp.Close()

End Sub
</script>
 
A

Armin Zingler

L

les

I don't know what's your intention. You wanted to get the bytes from a
stream in a certain encoding, right?

Yes but getting the following error:

BC30518: Overload resolution failed because no accessible 'GetBytes'
can be called with these arguments:

Line 20: Dim d As Byte() =
System.Text.Encoding.ASCII.GetBytes(readStream)


<%@ Page Language="VB" debug="True"%>
<%@ import namespace="system.io"%>
<%@ Import Namespace="System.Text" %>
<%@ import namespace="system.xml"%>
<%@ import Namespace="System.Net" %>
<%@ import Namespace="System.Web" %>
<Script Language="vb" runat="server">
Sub Page_Load(s as object, e as eventargs)

'Creates a streamreader from an xml file
Dim HttpWReq As HttpWebRequest =
CType(WebRequest.Create("http://server/datafile.xml"), HttpWebRequest)
Dim HttpWResp As HttpWebResponse = CType(HttpWReq.GetResponse(),
HttpWebResponse)
Dim receiveStream As Stream = HttpWResp.GetResponseStream()
Dim encode As Encoding =
system.Text.Encoding.GetEncoding("ISO-8859-1")
Dim readStream As New StreamReader(receiveStream, encode)

'post readstream to target server
Dim web As New System.Net.WebClient()
web.Headers.Add("Content-Type", "text/xml")
Dim d As Byte() = System.Text.Encoding.ASCII.GetBytes(readStream)
Dim res As Byte() = web.UploadData("http://targetserver/postpage",
"POST", d)
Console.Write(System.Text.Encoding.ASCII.GetString(res))
response.write (System.Text.Encoding.ASCII.GetString(res))

readStream.Close()
HttpWResp.Close()

End Sub
</script>
 
A

Armin Zingler

Yes but getting the following error:

Now we are as far as yesterday.

What do you want to do?? What is your intention??

You can NOT pass a streamreader to the GetBytes function. You can pass a
string to the GetBytes function. I don't know which string you want to pass.
I assume, you first want to read the string from the Streamreader and then
pass it to GetBytes. Is this right or wrong? If it is right, use the
Streamreaders ReadLine or Readtoend method. Then you have a string and you
can pass it to GetBytes. Where is the problem with doing it? Or is it not
what you want to do? I don't know.
 
L

les

Thanks for persevering with me Armin.
It sounds like you are describing exactly what I want to do, but I
don't know how to apply the ReadLine or Readtoend method to my
existing code.
Leslie
 
A

Armin Zingler

Thanks for persevering with me Armin.
It sounds like you are describing exactly what I want to do, but I
don't know how to apply the ReadLine or Readtoend method to my
existing code.
Leslie


You don't know how to call a method?

- WebRequest.Create
- HttpWReq.GetResponse
- HttpWResp.GetResponseStream
- Encoding.GetEncoding

These are all method calls in your code, so I think you do know how to call
a method. Sorry, I don't understand.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
L

les

I'm not sure I can describe the problem any better. I don't have much
experience of vb.net, so I'm hoping someone can show how to change my
code to use readline or readtoend as you sugested.
 
A

Armin Zingler

I'm not sure I can describe the problem any better. I don't have
much experience of vb.net, so I'm hoping someone can show how to
change my code to use readline or readtoend as you sugested.

You don't tell me what you want, so I can't help you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top