Click here to Skip to main content
14,825,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I try show listview with data json from web service but i got error in
var response = await api.getAllUserGoogle();


it is message error :
Response status code does not indicate success: 500 (Internal Server Error)


It is my data json from webservice
{"isSuccess":true,"resultMessage":"","data":
[{"password":"MnwPzyBdAZBrDV6xMHoIzg","userid":138,"email":"gusssion@gmail.com","username":"gussion"},{"password":"PFjQJkorLvR+ilWUWdq1Yw","userid":98,"email":"vania@gmail.com","username":"vania"},{"password":"LRmayI3ClJtVWijRyhR3Fg","userid":106,"email":"yuli@gmail.com","username":"yuli"}]}


It is my coding:

ApiInterface.cs
interface ApiInterface
    {
        [Post("/getAllUser")]
        Task<Data_ReturnResult> getAllUser();
    }


Data_ReturnResult
[Serializable]
    public class Data_ReturnResult
    {
        public Boolean isSuccess;
        public String resultMessage;
        public object data;

        public static Data_ReturnResult createReturnResult(Boolean isSuccess, String resultMessage, object data = null)
        {
            Data_ReturnResult result = new Data_ReturnResult();
            result.isSuccess = isSuccess;
            result.resultMessage = resultMessage;
            result.data = data;
            return result;
        }
        public static String createReturnResultInJson(Boolean isSuccess, String resultMessage, object data = null)
        {
            Data_ReturnResult result = createReturnResult(isSuccess, resultMessage, data);
            return JsonConvert.SerializeObject(result);
        }
    }


MainPage.xml
<StackLayout>

    <ListView
        x:Name="MyListView">
        <ListView.ItemTemplate>
            <DataTemplate>
                <TextCell Text="{Binding Username}" TextColor="Black"/>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

</StackLayout>


MainPage.xaml.cs
public partial class MainPage : ContentPage
    {

        private ApiInterface api;
        public List<User> users { get; set; }
        
        public class User
        {
            String password;
            String userId;
            String email;
            String username;

            public string Password { get => password; set => password = value; }

            public string UserId { get => userId; set => userId = value; }

            public string Email { get => email; set => email = value; }

            public string Username { get => username; set => username = value; }
        }

        public MainPage()
        {
            InitializeComponent();

            api = RestService.For<ApiInterface>("http://192.168.0.185/webservice/webservice.asmx");
            _ = CallApi();
        }

        async Task CallApi()
        {
            var response = await api.getAllUsers();
            MyListView.ItemsSource = response.ToString();

        }

    }


WebService
[WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public void getAllUsers()
        {
            DbAccessConnection conn = getActiveConnection();

            if (conn == null)
                return;

            try
            {
                beginTransaction(conn);
                
                User users = new User(conn);
                DataSet ds = new DataSet();
                string tbName = "User";

                users.getAll(ds, tbName);
                DataTable dtTbl = ds.Tables[tbName];

                List<Dictionary<String, object>> lsOfDtTbl = Tools.convertDataTableToList(dtTbl);

                Responder.writeResponse(true, "", lsOfDtTbl );
                commitTransaction(conn);
            }
            catch (Exception ex)
            {
                rollbackTransaction(conn);
                Responder.writeResponse(false, ex.Message);
            }
        }


What I have tried:

Could you help me how to fix it ?
Posted
Updated 28-Feb-20 20:46pm
v3

1 solution

C#
MyListView.ItemsSource
must be an
C#
IEnumerable<T>
instead of
C#
string
   
Comments
Rey21 29-Feb-20 2:48am
   
but i have a problem with message 500(Internal Server Error), and if i running my webservice it is success execute method getAllUsers. Could you help me ?
Cahyo DWC 1-Mar-20 17:32pm
   
500(Internal Server Error) came from your backend, ensure the code in your backend server is correct and run with no error

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900