0

I'm trying to test why my server is responding with 500 error when I send a large image (627 kb) as binary from the client. So, I brought the values the client sent in fiddler in the same machine the server is at. I kept increasing & decreasing the number of binary value. I'm marking the beginning of the post method with a break point and then at every test I check the object if it is null or not: enter image description here

the entity has a property for value called: ImageDataString of type string, which houses the binary values.

I noticed that if I increase 1 more character to my post at the arrow in fiddler, the object becomes null enter image description here

Whose limit is invalidating the post request, Fiddler or C# OData Api? In fact my image body is much more than those lengths. It can be up to 10 mg, what should I do to send large images and be able to test sending their binaries in fiddler!?

user1019042
  • 2,428
  • 9
  • 43
  • 85
  • Neither, it's IIS's default limit of 4 MB. Try actually reading the "500 error" and research it. – CodeCaster Jun 03 '16 at 07:53
  • I'm halting the execution from the moment it is initiated from fiddler to the api, by the break point I mentioned above; therefore, there is no error yet. so, it is the IIS, good to know. thx – user1019042 Jun 03 '16 at 08:19
  • @CodeCaster, when the maximum content length of IIS is exceeded [a 404 is be returned not a 500](https://www.iis.net/configreference/system.webserver/security/requestfiltering/requestlimits). However the content length of 4194304 Bytes = 4096 KB = 4 MB does indeed indicate that the default content length limit of IIS is exceeded. Weird. – Good Night Nerd Pride Jun 03 '16 at 08:52
  • @user1019042, what is the exact error you are getting? Is there a reason phrase returned with the HTTP status code? Have you tried [increasing the maximum request length](http://stackoverflow.com/questions/3853767/maximum-request-length-exceeded)? – Good Night Nerd Pride Jun 03 '16 at 08:54
  • @Abbondanza PROGRESS! Yes, i followed the link you noted and added the web.config setting and it let me added more characters. I still have many values to test but I thought I should come and express gratitude. Please add it as an answer so I mark it so. Note: I wasn't getting an error. I was just trying to 'watch' the object at the api side with the breakpoint to see it if has a value or null. I needed it to be populated not null. there was a character count breaker where it would show object populated or null. – user1019042 Jun 03 '16 at 09:15
  • @user1019042, I updated my answer. – Good Night Nerd Pride Jun 03 '16 at 09:24
  • @Abbondanza I'm back to report that now I can send my image with no issue! thanks. Please mark your comment as an answer. – user1019042 Jun 03 '16 at 09:27

1 Answers1

2

Your request is probably exceeding the maximum content length limit of IIS. Adjust it in your Web.config:

<configuration>
    <system.web>
        <httpRuntime maxRequestLength="<upper limit in KB>" />
    </system.web>
</configuration>

For IIS versions >=7 you have to configure this value as well:

 <system.webServer>
   <security>
      <requestFiltering>
         <requestLimits maxAllowedContentLength="<upper limit in Bytes>" />
      </requestFiltering>
   </security>
 </system.webServer>

Another problem you might run into is that the base 64 decoding could fail if you added random characters to the request body.

When you encode data with base 64 the output string will be padded to have a length divisible by 3. If you add a random character to the base 64 string the padding will be wrong and thus the decoding will fail.

If that is the case then the server will throw a FormatException with the message "Invalid length for a Base-64 char array or string." internally which in turns results in the HTTP status code 500 (Internal server error).

Community
  • 1
  • 1
Good Night Nerd Pride
  • 8,245
  • 4
  • 49
  • 65
  • 1
    I'm not at the decoding stage yet. I'm at the stage of passing different length string from fiddler and interrupting the process the execution hit the top of the method in the api to see if the object has a value or not. are you saying that the server (iis in this case) will try to do the decoding itself right when I send the request from fiddler and before it it hit the api!? – user1019042 Jun 03 '16 at 08:23