Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to send image from webservice to website

Status
Not open for further replies.

GeertVerhoeven

Technical User
Oct 7, 2001
142
BE
Hi all,

I have a webservice that creates an image. I want to show the result of that image on my website. The website and webservice are on different servers. There is a VPN line between both servers.

What is the best way to sent the image to my website?
- save the file on a share
- sent a stream from the webservice to the site (if it is possible to do)
- save the file to (if possible)
- ...

Thanks in advance,

Geert
 
I would have the server side of your web page do the following:

- Invoke the webservice method for generating the image

- Have the webservice method return a URL to the newly created image

- Have the ASP server-side code pull the file locally to a point it can publish using HTTP get.

I suspect trying to PUSH the file from the webservice to the website will give you headache, as will trying to return it as a stream. Your Webservice is hosted via ASP.NET so sharing the newly generated file as an image to be gotten is pretty easy.

TJR
 
If the client machine is A:
Webserver is on server B:
Images are on server C:

(A) may have access to (B) while (A) does not have access to (C).
If this is the scenerio then you will have to move the Bytes as a stream from (C) to (B) so (B) can serve it to (A).

In your web page you point the image to a dynamic aspx rather then a hard file. The aspx below will act as if you were requesting the image directly from server (C).

<img src="showimages.aspx?imagename=house.jpg" />

Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        Dim outPutFormat As System.Drawing.Imaging.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg
        Dim contType As String = "image/jpeg"
        Dim ImageName As String = Request("ImageName")
        Dim stmMemory As IO.MemoryStream = New IO.MemoryStream
        Dim myimg As System.Drawing.Bitmap = New System.Drawing.Bitmap("E:\somefolder\" & ImageName)
        Response.Clear()
        Response.ContentType = contType
        myimg.Save(stmMemory, outPutFormat)
        stmMemory.WriteTo(Response.OutputStream)
        Response.End()

    End Sub
 
The web service should be able to send a serialized bitmap if you don't want to actually store the image to disk anywhere.

It would look something like:

Code:
//page load
Bitmap bmp = myService.GetImage( "some argument" );
bmp.Save( Response.OutputStream, ImageFormat.Jpeg );
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top