Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7747263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:29:09+00:00 2026-06-01T10:29:09+00:00

So I have wcf rest service which succesfuly runs from a console app, if

  • 0

So I have wcf rest service which succesfuly runs from a console app, if I navigate to: http://localhost:8000/Service/picture/300/400 my image is displayed note the 300/400 sets the width and height of the image within the body of the html page.

The code looks like this:

namespace WcfServiceLibrary1
{
    [ServiceContract]
    public interface IReceiveData
    {
        [OperationContract]
        [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Xml, UriTemplate = "picture/{width}/{height}")]
        Stream GetImage(string width, string height);
    }
    public class RawDataService : IReceiveData
    {
        public Stream GetImage(string width, string height)
        {
                int w, h;

                if (!Int32.TryParse(width, out w))
                {
                    w = 640;
                }
                // Handle error
                if (!Int32.TryParse(height, out h))
                {
                    h = 400;
                }
            Bitmap bitmap = new Bitmap(w, h); 
            for (int i = 0; i < bitmap.Width; i++)
            {
                for (int j = 0; j < bitmap.Height; j++)
                {
                    bitmap.SetPixel(i, j, (Math.Abs(i - j) < 2) ? Color.Blue : Color.Yellow);
                }
            }
            MemoryStream ms = new MemoryStream();
            bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            ms.Position = 0;
            WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
            return ms;
        }
    }
}

What I want to do now is use a client application “my windows form app” and add that image into a picturebox. Im abit stuck as to how this can be achieved as I would like the width and height of the image from my wcf rest service to be set by the width and height of the picturebox. I have tryed this but on two of the lines have errors and im not even sure if it will work as the code for my wcf rest service seperates width and height with a “/” if you notice in the url.

    string uri = "http://localhost:8080/Service/picture";
    private void button1_Click(object sender, EventArgs e)
    {

        StringBuilder sb = new StringBuilder();
        sb.AppendLine("<picture>");
        sb.AppendLine("<width>" + pictureBox1.Image.Width + "</width>");
        // the url looks like this http://localhost:8080/Service/picture/300/400 when accessing the image so I am trying to set this here
        sb.AppendLine("<height>" + pictureBox1.Image.Height + "</height>");
        sb.AppendLine("</picture>");
        string picture = sb.ToString();
        byte[] getimage = Encoding.UTF8.GetBytes(picture); // not sure this is right
        HttpWebRequest req = WebRequest.Create(uri); //cant convert webrequest to httpwebrequest
        req.Method = "GET";
        req.ContentType = "image/jpg";
        req.ContentLength = getimage.Length; 
        MemoryStream reqStrm = req.GetRequestStream(); //cant convert IO stream to IO Memory stream
        reqStrm.Write(getimage, 0, getimage.Length); 
        reqStrm.Close();
        HttpWebResponse resp = req.GetResponse(); // cant convert web respone to httpwebresponse
        MessageBox.Show(resp.StatusDescription);
        pictureBox1.Image = Image.FromStream(reqStrm);
        reqStrm.Close();
        resp.Close();
    }

So just wondering if some one could help me out with this futile attempt at adding a variable image size from my rest service to a picture box on button click.

This is the host app aswell:

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string baseAddress = "http://" + Environment.MachineName + ":8000/Service";
            ServiceHost host = new ServiceHost(typeof(RawDataService), new Uri(baseAddress));
            host.AddServiceEndpoint(typeof(IReceiveData), new WebHttpBinding(), "").Behaviors.Add(new WebHttpBehavior());
            host.Open();
            Console.WriteLine("Host opened");
            Console.ReadLine();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:29:11+00:00Added an answer on June 1, 2026 at 10:29 am

    A WinForms-based method to get the image with variable width and height would look like this:

    public Image GetImage(int width, int height)
    {
        string uri = string.Format("http://localhost:8000/Service/picture/{0}/{1}", width, height);
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
    
        using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
        {
            using (Stream stream = response.GetResponseStream())
            {
                return new Bitmap(stream);
            }
        }
    }
    

    You might put the image to a PictureBox like this:

    private void Form1_Load(object sender, EventArgs e)
    {
        pictureBox.Image = GetImage(400, 500); // or any other size here
    }
    

    In WPF you would do something like this:

    public ImageSource GetImage(int width, int height)
    {
        string uri = string.Format("http://localhost:8000/Service/picture/{0}/{1}", width, height);
        return BitmapFrame.Create(new Uri(uri));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a wcf 3.5 rest service which gets a dataset from database, i
If I have a wcf rest service such as http://somedomain.com/service.svc/uniqueid/somemethod/parameter1 then is there a
I have a WCF REST service which needs to invoke a URL (could be
I have a WCF REST Service which accepts a JSON string One of the
I have a WCF-REST service with one method which returns a string: [ServiceContract] public
what is the ActionFilterAttribute equivalent in WCF ? I have a REST service which
I have a WCF 4 REST service which does some processing and then returns
I have a WCF REST Web Service which returns POCO entities generated by Entity
I have created a REST service using WCF for communicating with BLL/DAL from UI.
I have written a REST Service in WCF in which I have created a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.