Forum Xamarin Xamarin.Forms

Web API and Xamarin

We have web api like below:

     public CustomAuthenticateModel AuthenticateByUsername(LoginModel model)
                    return employeeService.AuthenticateByUsername(model.Username, model.AdDomain, model.IsAdAuthentication);

In my PCL Project I am trying to access via:

                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.



  • JonathanTwiteJonathanTwite USMember ✭✭

    Did you solve this?

  • Hardik_MistryHardik_Mistry USMember, University ✭✭✭
    edited May 2017


    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 ( 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.