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 8851079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:03:41+00:00 2026-06-14T13:03:41+00:00

So I am trying to send an image from the client side to the

  • 0

So I am trying to send an image from the client side to the service.

Service definition looks like this (implementation is nothing fancy and It doesn’t reach there so excluding that code):

[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "Image")]
Stream Image(byte [] Image);

The calling client looks like this:

public static byte[] ImageToByte(Image img)
{
    ImageConverter converter = new ImageConverter();
    return (byte[])converter.ConvertTo(img, typeof(byte[]));
}

string uri = "http://localhost:8000/RestfulService/Image";

Bitmap img = new Bitmap("Random.jpg");
byte[] byteArray = ImageToByte(img);

var request = WebRequest.Create(uri) as HttpWebRequest;

if (request != null)
{
    request.ContentType = "application/json";
    request.Method = "POST";
}

if (request.Method == "POST")
{
    request.ContentLength = byteArray.Length;
    Stream postStream = request.GetRequestStream();
    postStream.Write(byteArray, 0, byteArray.Length);
    postStream.Close();
}

if (request != null)
{
    var response = request.GetResponse() as HttpWebResponse;

It throws an exception at the last line with

The remote server returned an error: (400) Bad Request.

I’ve tried all possible things I can think of for:

request.ContentType

  • 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-14T13:03:43+00:00Added an answer on June 14, 2026 at 1:03 pm

    Where I am doing something similar (posting a raw file) I accept the input as a Stream (not byte[]).

    Also I would expect the content type of the request to be application/octet-stream although “application/json; charset=utf-8” would probably work.

    When I was testing this, using Stream as the input parameter type or return value of the WebInvoke method was the trick to get the raw body of the request / response.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to send more than one image file from a client to the
I'm trying to send a BitmapSource from my WCF service to my client app.
I am trying to send an image from a Java desktop application to a
I have to send a name and a link from client side to the
What i'm trying to do is transfer an image from the web service to
I am trying to send camera image from one intent to another intent to
Hi so I'm trying to send an image (png) from the sdcard in an
I'm trying to send an image from C++ to C# with an interop (marshaling)
I am trying to send an email with an image attachment from Java. I
I have this simple Server/Client application. I'm trying to get the Server to send

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.