Results 1 to 8 of 8

Thread: binary data through web service

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    Prague, Czech Republic
    Posts
    350

    Question binary data through web service

    How can I return for example a picture (or any other binary file) by WebMethod function?

    Thanks

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    hmm good question

    Perhaps create a GDI Graphics object(dont know the namespace off the top of my head) that the Function can return

    Code:
    <Webmethod()>Public Function myImage() As Graphics
    
    End Function
    Do some searching for GDI+ to find info on loading an Image to the Graphics object and whatever namespaces needed

    IO namespaces/classes might be able to be used for other files..
    Cant be 100% sure on this though.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    Prague, Czech Republic
    Posts
    350
    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

    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?

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Ill do some looking around to see what I can find since this is an interesting idea.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    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.

    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    Prague, Czech Republic
    Posts
    350
    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 (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.

  7. #7
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    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.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 1999
    Location
    Prague, Czech Republic
    Posts
    350
    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... ... unless I force IE to encode and display the image itself, as in MHT files. But this would limite reciever to use only IE...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width