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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:18:34+00:00 2026-05-27T17:18:34+00:00

I have a JSON server (WCF REST) with a JSON POST method that accepts

  • 0

I have a JSON server (WCF REST) with a JSON POST method that accepts an object containing id (string) and an image (byte[]):

    [DataContract(Name = "image")]
public class CustomImage
{
    [DataMember(Name = "id")]
    public string Id { get; set; }
    [DataMember(Name = "imagestream")]
    public byte[] ImageStream { get; set; }
}

I have managed to send data to the server from an C# console application with the following code:` byte[] bytearray = null;

        Stream stream = File.OpenRead(@"c:\temp\snow.jpg");
        stream.Seek(0, SeekOrigin.Begin);
        bytearray = new byte[stream.Length];
        int count = 0;
        while (count < stream.Length)
        {
            bytearray[count++] = Convert.ToByte(stream.ReadByte());
        }

        CustomImage image = new CustomImage {Id = "43"};
        image.ImageStream = bytearray;
        WebClient Proxy1 = new WebClient();

        Proxy1.Headers["Content-type"] = "application/json";
        MemoryStream ms = new MemoryStream();
        DataContractJsonSerializer serializerToUpload = new DataContractJsonSerializer(typeof (CustomImage));
        serializerToUpload.WriteObject(ms, image);
        byte[] data = Proxy1.UploadData("http://localhost:5465/MyService/file/post", "POST", ms.ToArray());`

But I am not able to get this to work in my Android-application. I am using the following code:` public boolean UploadImage(String id, byte[] imageData) throws JSONException, UnsupportedEncodingException {
BasicHttpContext localContext = new BasicHttpContext();
DefaultHttpClient httpClient = getHttpClient();

    HttpResponse response = null;
    HttpPost httpost = null;

    String url = String.format("file/post");
    url = String.format("%s/%s", API_ROOT, url);

    httpost = new HttpPost(url);

    //JSONArray jsonArray = new JSONArray();      
    //for(int i=0;i<imageData.length;i++) {
    //    jsonArray.put(imageData[i]);
    //}

    JSONObject data = new JSONObject();
    data.put("id", id);
    data.put("imagestream", imageData);
    data.put("imagestream", jsonArray);


    StringEntity se = null;
    se = new StringEntity(data.toString());

    httpost.setEntity(se);

    response = null;
    httpost.setHeader("Accept", "application/json");
    httpost.setHeader("Content-type", "application/json");

    try {

        response = httpClient.execute(httpost, localContext);
    } catch (ClientProtocolException e) {
        // System.out.println("HTTPHelp : ClientProtocolException : " +
        // e);
    } catch (IOException e) {
        // System.out.println("HTTPHelp : IOException : " + e);
    }

    if (response != null && response.getStatusLine() != null
            && response.getStatusLine().getStatusCode() == 200) {

        return true;
    }
    return false;
}

But all I am getting is:

`The request body could not be deserialized. End element imageStream from namespace ” expected. Found text ‘[B@406bb748’.

  • 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-05-27T17:18:35+00:00Added an answer on May 27, 2026 at 5:18 pm

    Check your image. Maybe it needs to be Base64 encoded before being submitted.

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

Sidebar

Related Questions

I have a WCF REST Service which accepts a JSON string One of the
I have a question about type casting. I have the following JSON String: {server:clients,method:whoIs,arguments:[hello]}
I have developed a sample WCF REST service that accepts that creates an Order
I have a WCF service that received a JSON request with a byte array
I'm have an action /json that returns json from the server. Unfortunately in IE,
I have an jQuery JSON request, that loads some JSON from another server (ex.
I have a server that I have no control over, it's JSON based and
I have determined that my JSON, coming from the server, is valid (making the
I have one JSON that is coming in a string format. I need to
I have a simple WCF service that I call server side from code behind

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.