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

  • SEARCH
  • Home
  • 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 7778071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:18:16+00:00 2026-06-01T18:18:16+00:00

Noob WCF/REST question here! I need to build a simple web service (one method

  • 0

Noob WCF/REST question here!
I need to build a simple web service (one method for now), my preference would be for a REST/JSON type of architecture but I’m not sure this can be achieved in my case.

I know that it’s easy enough to serialize/deserialize complex objects into/from JSON while using a REST-based service. Even though I haven’t tested it yet, it also looks easy enough for a REST-based service to return an image.

However, my scenario may need to serve a mix of both. Below is an example of an object definition that can be returned:

class Response
{
  string myTitle;
  string myDate;
  Object myImage; 
}

I realize I could store the physical image wherever accessible and then simply return the URL as a string but I would like to avoid the overhead as much as possible.

Is it even possible?

Also note that I’m not committed to REST or JSON in any way, it’s simply that all the cool kids are using it so…

  • 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-01T18:18:17+00:00Added an answer on June 1, 2026 at 6:18 pm

    If you want the image as part of the JSON object, convert it into a serializable type. Easiest way is just to use its byte representation.

    System.Drawing.Image img = System.Drawing.Image.FromFile("filename");
    byte[] imgContent;
    using (System.IO.MemoryStream m = new System.IO.MemoryStream())
    {
        img.Save(m, img.RawFormat);
        imgContent = new byte[m.Length];
        const int count = 4096;
        byte[] buffer = new byte[4096];
        for (int i = 0; i < m.Length; i += count)
        {
            m.Read(buffer, i, (m.Length - i < count ? (int)(m.Length - i) : count));
            buffer.CopyTo(imgContent, i);
        }
    }
    myResponse.myImage = imgContent;
    

    EDIT: As the OP found, there is a much simpler/quicker way to write:

    System.Drawing.Image img = System.Drawing.Image.FromFile("filename");
    using (System.IO.MemoryStream m = new System.IO.MemoryStream())
    {
        img.Save(m, img.RawFormat);
        myResponse.myImage = m.ToArray();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Noob dumb question, no doubt -- but here it is: Trying to tutorialize myself
noob question on c#: how to create a one-dimensional dynamic array? And how to
Noob question for Ruby on Rails- here's an example of my situation: If I
Noob question here! I have an array with hashes that looks like this: arr
Noob here - I'm working on a simple Javascript calculator, and I'm using lists
Super noob question here... The file source: www.mysite.com/blah/blah/customdir/ajax/folder/file.php and I want to include a
Another noob question that seems like it should be simple: Thanks to the help
PowerShell noob question here. I have groups of servers that are listed in separate
I'm a noob to calling WCF web services, so am hoping this is an
I need to create a web service to collect data from my customer’s applications.

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.