Web API and Xamarin

Hi,
We have web api like below:

     [HttpPost]
     public CustomAuthenticateModel AuthenticateByUsername(LoginModel model)
            {
                    return employeeService.AuthenticateByUsername(model.Username, model.AdDomain, model.IsAdAuthentication);
            }

In my PCL Project I am trying to access via:

    try
            {
                HttpResponseMessage response = null;
                LoginModel l = new LoginModel();
                l.Username = model.Email;
                response = await apiClient.PostAsJsonAsync(uri, l); // Exception is fired at this line
        }
    catch(exception etc){}

and every time I am getting exception like:

ex = {System.TypeInitializationException: The type initializer for 'System.Net.Http.FormattingUtilities' threw an exception. ---> System.NotImplementedException: The method or operation is not implemented.
  at System.Runtime.Serialization.XsdDataContractExporte...

Please help in this problem.
This is an existing project, all API consume Model Class object as parameter. what is the right way to do this? I am trying to use MVVM helper library for this project.

Regards--
AG

Answers

  • JonathanTwiteJonathanTwite ✭✭ USMember ✭✭

    Did you solve this?

  • Hardik_MistryHardik_Mistry ✭✭✭ USMember, University ✭✭✭
    edited May 2017

    @AnirbanGhosh

    The exception states that the method (the url you are trying to reach) is not implemented in your controller.

    Verify your route as well that you had typed in the apiClient class.

    I notice you are trying to perform POST operation, can you verify if the route (http://yourdomain.com/api/account/auth) does implement POST operation or PUT or nothing at all, the tricky part is API would not complain about the implementation as far as it can compile and execute.

    I would recommend you to add Swagger to your WebAPI to help you understand underlying controller and related implementation without digging too much into the code.

    Share your inputs if this helped or did not help.

Sign In or Register to comment.