0

i m facing a problem in which when i send a small size byte array

byte[] s = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

then it will received and inserted in database successfully but when it comes to a bytes array of image converted to a bytes[] then i will show an exception

"The request failed with HTTP status 404: Not Found."

it does not show that "maximum limit exceed" or something like that. what should i do? here is the screen shot

enter image description here

it send the byte array that is commented but the array in arguments is the bitmap converted to byte array.

- Edited

Here is the code of receiving end in web service

 [WebMethod]
 public bool TakeScreenShotResponseBack(string ip, byte[] screenShot)
    {
        dbOpts = new DatabaseOperation();

        if (dbOpts.InsertBitmapResponse(ip, screenShot))
            return true;
        else
            return false;
    }

and here is the sending side code

    public bool ScreenShotResponse(string ip, byte[] ss)
    {
        response = new MyService.MasterWebService();
        try
        {
            //byte[] s = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            if (response.TakeScreenShotResponseBack(ip, ss))
                return true;
            else
                return false;
        }
        catch
        {
            return false;
        }
    }
Assassino
  • 31
  • 1
  • 3
  • 11
  • FYI - posting code and full exception details works a lot better than a screenshot. – Jon B Apr 16 '14 at 17:25
  • i have posted it @Jon B – Assassino Apr 16 '14 at 17:38
  • Thanks. I think jalgames is on to something. I would try changing to base64 string instead of byte[]. Side note: you're doing `if (true) { reutrn true; } else { return false; }`, which is a little silly (just return the result of your web method call). – Jon B Apr 16 '14 at 17:42
  • okay :P thanku for correction – Assassino Apr 16 '14 at 17:44

2 Answers2

0

I had this problem myself and it seems like the reason is that a non base64-encoded image may contain bytes that terminate a post request etc. so the request will be invalid.

Another reason may be your webprovider. A freehoster I had tried didn't work, but when I moved to another hoster without changing a single line everything worked perfectly.

I recommend you to use RestSharp:

RestRequest request = new RestRequest("url", Method.POST);
request.AddParameter("image",  Convert.ToBase64String(imagestream.ToArray());
RestClient client = new RestClient();
client.ExecuteAsync(request, (response) =>
{
    //Do something with the response
}
jalgames
  • 781
  • 4
  • 23
-1

Try to convert your image with this:

  public byte[] FileToByteArray(string fileName)
  {

       byte[] buff = null;

       if (fileName != null && fileName != "" && File.Exists(fileName))

       {

          buff = File.ReadAllBytes(fileName);

       }
        return buff;
    }

In my database the column for the picture is type image.I hade the same problem and i fixed it with this.

Jon B
  • 51,025
  • 31
  • 133
  • 161
  • the image i had to convert is in Bitmap already, m not reading it from HDD, bcz my code takes a screenshot and i have to convert it to bytes. any other suggestion plz? – Assassino Apr 16 '14 at 17:51