How to downlaod an image returned by a webservice

    Allgemeine Diskussion

  • Hi,

    I have a moss 2007 application and I am using C# for development. There are images stored on one of the servers which I need to access but the issue is that this server is not exposed to the internet but my application is accessible on the net. So when I call the images from inside the network, I am able to access these images but from outside the network I am unable to do so.

    So there is an alternative that we are implementing. We are going to call a webservice to retrieve images. The web service would accept a User ID as a parameter and return the appropriate image associated with that ID so for every different user, I would be getting a different image. Once I receive the image from the web service, I would need to open the image in a new window.

    I am able to call the webservice and pass the required parameter. I would like to know how do I receive/download this image that is being returned from the webservice and then how would I open this image in a new window.

    Please let me know if anyone has done this before. Please share some articles specifying how to achieve this if they are available.

    Thanks in advance.



    Mittwoch, 14. März 2012 08:25

Alle Antworten

  • Hi Raj...

    Could you please let us know in which format the web service is returning the image?

    Success is not to be pursued; it is to be attracted by the person we become.

    Mittwoch, 14. März 2012 08:39
  • Hi Shailu,

    The webservice is not designed yet. It would be created by a different team once we specify how we need it.

    I will be consuming the webservice by using WCF, creating a channelfactory etc.

    What would you suggest be the best approach here to recieve the image?



    • Bearbeitet Raj190 Mittwoch, 14. März 2012 12:04
    Mittwoch, 14. März 2012 10:05
  • Hi,

    Please let me know if anyone has some knowledge about this. Your help would be greately appreciated.



    Donnerstag, 15. März 2012 06:14
  • Hi Raj,
    you may use Http to download.
    Below is the sample program which might help you:-

                 * get URL from web service by using "ows_EncodedAbsUrl";
                and get filename from web service by using  "ows_LinkFilename";
                 Then pass these into this method
            public void DownloadDocs(string URL, string FileName)
                HttpWebRequest request;
                HttpWebResponse response;
                    request = (HttpWebRequest)WebRequest.Create(URL);
                    request.Credentials = System.Net.CredentialCache.DefaultCredentials;
                    request.Timeout = 10000;
                    request.AllowWriteStreamBuffering = false;
                    response = (HttpWebResponse)request.GetResponse();
                    Stream stream = response.GetResponseStream();
                    string filePath = @"C:\DownloadDocument\";
                    FileStream fs = new FileStream(filepath + FileName, FileMode.Create);
                    byte[] read = new byte[4096];
                    int count = stream.Read(read, 0, read.Length);
                    while (count > 0)
                        fs.Write(read, 0, count);
                        count = stream.Read(read, 0, read.Length);
                catch (Exception ex)
    follow me:

    • Bearbeitet Avinash Dad Dienstag, 10. April 2012 07:40 Edited my blog link
    Freitag, 16. März 2012 07:48