0
votes

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 ?

1
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)Nilesh
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/classilansch
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" />Nilesh
But wouldnt it be wise to compress the json string instead?ilansch

1 Answers

1
votes

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.