0

I've been working on this issue for a day or two.. I am new to .asp Web API.

What is the proper way of uploading/sending a class from my C# .net 4.0 application to Web API controller, The C# application is on computer A, the WebAPI is on computer B.

Till now I Used HttpRequestMessage and StringContent as content and sending using HttpClient class. I have successfully .Put the class as json, but now the class has got a bit bigger, and i need to compress and send it.

What i thought i need to do is take the class, json it, zip it, and send as zipped byte[].
Is this the correct approach ?
I have posted some question and was trying to find good guides - did not succeed.

This is link to previous post:
C# .net 4.0 Upload a file to .asp Web API

Maybe my approach is wrong ?

4
  • Are you using form post? If yes you can generate a json object and send it inside a form body. In the WebApi method use[FromBody] for the method parameter. something like public void MyMethod([FromBody] MyClass inputClass) Commented Sep 12, 2013 at 7:18
  • I did exactly what you wrote, and its working ok, but as i wrote in the question.. now my JSON is too big and if i try to send it same way, i get exception in the controller that content is too big. i must compress the JSON/class Commented Sep 12, 2013 at 7:26
  • I think you can add a setting in the Web.Config for the size of content that can be posted to the server! its something like <httpRuntime maxRequestLength="Put the max size here lik 1000000" /> Commented Sep 12, 2013 at 7:30
  • But wouldnt it be wise to compress the json string instead? Commented Sep 12, 2013 at 7:37

1 Answer 1

1

As you know native format of WebAPI is JSON so I suggest that you pass the JSON payload as is. Before you decide to compress it I recommend that you read the numbers and their performance here in terms of records and size. http://josh.zeigler.us/technology/web-development/how-big-is-too-big-for-json/

Also, I would like to suggest that test the API call with some data before you decide to send as Byte array.

Hope this will help.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.