How can I return for example a picture (or any other binary file) by WebMethod function?
Thanks
Printable View
How can I return for example a picture (or any other binary file) by WebMethod function?
Thanks
hmm good question
Perhaps create a GDI Graphics object(dont know the namespace off the top of my head) that the Function can return
Do some searching for GDI+ to find info on loading an Image to the Graphics object and whatever namespaces neededCode:<Webmethod()>Public Function myImage() As Graphics
End Function
IO namespaces/classes might be able to be used for other files..
Cant be 100% sure on this though.
OK, I have tried this ;) :
1) Declare function as System.Drawing.Image
2) Declare any function with parameter of System.Drawing.Image type
3) Declare function as object, returning bounded System.Drawing.Image
:mad: First two failed during preparing the page, with exception System.Drawing.Image cannot be serialized because it doesn't have default public constructor or something like this, and the third throwed same exception as soon as I pressed 'invoke'...
Then I tried to declare any function with parameter of object, which I don't know, wheter it is functional, as I cannot test it through IE since "it doesn't support HTTP GET method". :(
Any ideas?:confused:
Ill do some looking around to see what I can find since this is an interesting idea.
ack.. doesnt look possible according to this
http://samples.gotdotnet.com/quickst...vicetypes.aspx
i guess the only option is to break it down into a byte array that the client would have to manually code to rebuild.
:(
This seems to be quite good argument. :(
However, I think there should be some better support for binaries (or text files as well) than splitting it into an array, what is not so good idea. Imagine, even sending <byte> and </byte> enlarges the file 7 times :eek: (in addition to spaces, bytes represented by string, and line feeds).
I don't believe realizing such simple services, as get an image, do some effects and return image, or translate documents or whatever else, will be too complicated, or?
Another poor idea - to encode the file (uuencode, mime) and to send it as long string or something.
well yeah as a string would be ok to...I really meant to say byte array or as a string.... Either way there just isnt any better option as now that I think about it, binary support would go outside the bounds of what xml does and I believe MS is trying to get away from adding propietary functionailty to open standards.
Well, it seems there is not any other possibility :(, so...
I have web service returning encoded image as string
I think there is no problem, encoding can be done manually, if not already present in some system libraries
Client is an ASP.NET page
which should encode and display the image. And here I have no idea how to transform a string into bitmap...
...unless... :D ... unless I force IE to encode and display the image itself, as in MHT files. But this would limite reciever to use only IE...