views:

25

answers:

2

Hi,

I've got asmx with method

[Webmethod]
public Ssytem.IO.Stream GetStream(string path)
{
...
}

and winforms application which has webreference to this webservice.

I cannot do something on my winforms application like something:

var myStream= (System.IO.Stream)client.GetStream(path);

because i

Cannot cast expression "MyWinformsApp.MyService.Stream" to Stream.

Why is that ?

A: 

Because your MyWinformsApp.MyService.Stream does not derive from System.IO.Stream ?! You are correctly prohibited from casting an object into something it isn't.

Johannes Rudolph
I doesn't have class Stream. I use in this webmethod System.IO.Stream
+1  A: 

You cannot return a Stream via a WebMethod. If you want to return the data in the file, there are a number of options, but the most straightforward is probably:

  • Read the file contents and base64 encode it.
  • Return the base64 encoded data.
  • On the client-side decode the data and save it back to a file.
chibacity