Issue with Web API Model Binding: Object passed to service is null only on iOS.

Hello All.

I have been running into a very strange issue, and I am not even sure if this is an issue with my app or the web service I am calling.

I have a Web Api Service with a Post method that accepts a complex parameter (it is my own custom object). In my Xamarin project I have some pretty straightforward code to call this service:

public async Task SubmitEReport(decimal amount, DateTime receivedDate, byte[] image)
HttpClient client = new HttpClient();

            var uri = new Uri("");

            var eReport = new eReport()
                UserName = "EMPLOYEE\" + Application.Current.Properties["username"].ToString(),
                Cost = amount,
                ReceivedDate= receivedDate,
                ReceiptImageExtension = "jpg",
                SubmittalDate = DateTime.Now,
                Image = image

            var json = JsonConvert.SerializeObject(eReport );

            var content = new System.Net.Http.StringContent(json, Encoding.UTF8, "application/json");

            content.Headers.Add("authorize-token", Application.Current.Properties["auth-token"] as string);

            HttpResponseMessage response = null;

            response = await client.PostAsync(uri, content);

            var eResult = new EResult()
                Success = response.IsSuccessStatusCode,
                ErrorMessage = response.ReasonPhrase


            return eResult ;
        catch (Exception ex)
            var errorResult = new eResult () { Success = false, ErrorMessage = ex.Message };
            return errorResult;

The issue that I am having is that, when I test this on an Android the code works as expected: the service is called, the object passed over is not null and has the data in it. In short, the parameter binding works as expected. The same is not so on iOS: when I call the service using the app on an iPhone, I can see that it is reaching the service and the Post method, but the parameter binding is not working correctly as the object I am passing over is always null.

Any help is appreciated.


  • PubuduGayanPubuduGayan NZMember ✭✭✭

    @JamesStarner I believe your not local host..

  • JamesStarnerJamesStarner USMember

    Hi Pubudu. I am unsure of exactly what you mean. Are you saying that I am having issue calling to the service because I am on localhost? As I mentioned, I am able to call this service correctly in the Android app, but not iPhone.

  • LobboLobbo GBMember ✭✭

    Hi did you get a solution to this? I am having the same issue accept for me iOS works and android doesn't. I'm posting to a Web API and when using the iOS app the complex object always arrives null

Sign In or Register to comment.