I have REST API Service. Below is API Controller method.
public class ExcelUploadController : ApiController
{
[HttpPost]
public async Task<HttpResponseMessage> Upload(HttpRequestMessage request)
{
if (!request.Content.IsMimeMultipartContent())
{
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
}
HttpPostedData postedData = await Request.Content.ParseMultipartAsync();
ProcessFile postedFile = new ProcessFile(postedData);
return new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(postedFile.Process())
};
}
}
It returns JSON data of uploaded excel.
And below is my client code that uses RESTSharp
int ReadWriteTimeout = -1;
RestClient restClient = new RestClient("https://restfulservice.domain.com");
RestRequest restRequest = new RestRequest("api/excelupload/Upload");
int readWriteTimeout = restRequest.ReadWriteTimeout > 0
? restRequest.ReadWriteTimeout
: ReadWriteTimeout;
restRequest.ReadWriteTimeout = -1;
restClient.Timeout = -1;
restClient.ReadWriteTimeout = -1;
restRequest.Method = Method.POST;
restRequest.AddHeader("Content-Type", "multipart/form-data");
restRequest.AddFile("content", location);
restRequest.AddParameter("DetailLineNumber", "4");
var response = restClient.Execute<List<ActualsDataViewModel>>(restRequest);
I am expecting my client to wait until service completes processing. But client is not waiting and response object is blank means statuscode is 0. And response.Data is null.
If I run the same REST API service in the localhost and replace below code in Client then it works perfectly fine.
RestClient restClient = new RestClient("http://localhost:5100");
Why if same service is running on server (IIS) then client is not waiting for the response?