I trying to display image in picture box. The application have two part.
First part is windows application, and second part is web service (asmx).
This is the code for windows application:
Public Sub PrikazSlike()
Dim p As localhost.Service1 = New localhost.Service1()
PictureBox1.Image = Image.FromStream(p.PictureShow())
End Sub
And this is the code for web service:
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.IO
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class Service1
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function PictureShow() As System.IO.MemoryStream
Dim client As New System.Net.WebClient()
Dim stream1 As New System.IO.MemoryStream()
Dim data As Byte() = client.DownloadData("http://www.psp-themes.net/.../assassins%20creed%203.jpg")
client.Dispose()
stream1.Write(data, 0, data.Length)
Return stream1
End Function
End Class
The problem is that function in web service does not return System.IO.MemoryStream data type so I getting error message can not convert:
Error 1 Value of type ‘WindowsApplication1.localhost.MemoryStream’ cannot be converted to ‘System.IO.Stream’.
How I can resolve this?
Many thanks!
Update (originally posted as an ‘answer’)
This is the update code for web service:
<WebMethod()> _
Public Function PrikazSlike() As Byte
Dim client As New System.Net.WebClient()
'Dim data As Byte
Dim data As Byte() = client.DownloadData("http://www.psp-themes.net/.../assassins%20creed%203.jpg")
Dim stream1 As New System.IO.MemoryStream(data)
client.Dispose()
stream1.Write(data, 0, data.Length)
Return Convert.ToByte(stream1)
End Function
End Class
This is the windows application code:
Public Sub Show.Picture()
Dim p As localhost.Service1 = New localhost.Service1()
PictureBox1.Image = Image.FromStream(p.PictureShow())
End Sub
Now I getting error:
Error 1 Value of type ‘Byte’ cannot be converted to ‘System.IO.Stream’.
The error message says that your method returns the type
WindowsApplication1.localhost.MemoryStreamand not aSystem.IO.MemoryStream.I suspect that your web service is set up to return a
MemoryStreamobject. Try to change it to return abyte[] array instead. On your receiving side retrieve the byte array and create aSystem.IO.MemoryStreamfrom that array.