# Visual Basic > Xamarin >  Not Getting Data From WebAPI

## kuldevbhasin

hi.
i am working on xamarin and created a web api for data transfer but not getting any data in the xamarin form. The web api is showing data in postman on local server but in xamarin the response is showing empty json. The same database is uploaded to the server and the data is present in it too

My Web API

```
   Public MyConConnection As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("SqlConnectionString").ToString())
 <Route("GetConsumerDetailsJSonInList")>
        Public Function GetConsumerJSonData(ByVal xCustNo As String) As List(Of ConsumerForLogin)
            Dim employeeData As List(Of ConsumerForLogin) = New List(Of ConsumerForLogin)()
            Dim obj As ConsumerForLogin()

            'employeeData.Add({1, "sdfshfkhsdkhf", "kjhkdfsdf", "sdfjsdkfsf", "sdfjskjfksf"})
            'employeeData.Add(New ConsumerForLogin {ConsumerNo="U010001", MyId = 1, Name = "Rohit Singh", Address = "kdflsdjklfdf", MobileNo = "12345" });


            Dim mcmd As String = "SELECT * FROM ConsumerMaster WHERE CustNo = @mCNo "

            Dim da_Temp As SqlDataAdapter = New SqlDataAdapter(mcmd, MyConConnection)
            da_Temp.SelectCommand.Parameters.AddWithValue("@mCNo", xCustNo)
            Dim ds_Temp As DataSet = New DataSet()
            Dim dTab As DataTable = New DataTable()
            da_Temp.Fill(ds_Temp, "ConsumerMaster")
            dTab = ds_Temp.Tables("ConsumerMaster")
            Dim iRowCount As Integer = dTab.Rows.Count - 1

            For i As Integer = 0 To iRowCount
                Dim irow As DataRow = dTab.Rows(i)
                Dim xmyId As Integer = Convert.ToUInt16(irow("myID").ToString())

                employeeData.Add(New ConsumerForLogin() With {
                .MyId = irow!MyID,
                .Name = irow!Name,
                .Address = irow!Address,
                .CustNo = irow!CustNo,
                .MobileNo = IIf(IsDBNull(irow!MobileNo), " ", irow!MobileNo)
            })



            Next
            Return employeeData

        End Function
```






```
namespace UMCWaterBilling.Models
{
    public class ConsumerInformation
    {
        public int MyId { get; set; }
        public string CustNo { get; set; }
        public string Name { get; set; }
        public string Address { get; set; }
        public string MobileNo { get; set; }
    }
}
```

my Xamarin Code 


```
  var httpClient = new HttpClient();
            var response = await httpClient.GetStringAsync(AppSettings.ApiUrl + "Consumer/GetConsumerDetailsJSonInList?xCustNo='" + txtCustNo.Text + "'");
            var login = JsonConvert.DeserializeObject<List<ConsumerInformation>>(response);

            ConsumerDetails.ItemsSource = login;
```



```
<StackLayout>
                                <ListView x:Name="ConsumerDetails">
                                    <ListView.ItemTemplate>
                                        <DataTemplate>
                                            <StackLayout>
                                                <Label Text="{Binding Name}"></Label>
                                                <Label Text="{Binding Address}"></Label>
                                                <Label Text="{Binding CustNo}"></Label>
                                                <Label Text="{Binding MyID}"></Label>
                                                <Label Text="{Binding MobileNo}"></Label>
                                            </StackLayout>
                                        </DataTemplate>
                                    </ListView.ItemTemplate>
                                </ListView>
                            </StackLayout>
```

pls. guide as to what am i doing wrong. thanks

----------


## jmcilhinney

I doubt that you should have single quotes in your URL when you call GetStringAsync.

----------


## kuldevbhasin

hi thanks for pointing out the silly mistake i was doing 
for simplifying the things  i changed the code in web api to (just to try out as i was getting an error) : 


```
 Dim employeeData As List(Of ConsumerForLogin) = New List(Of ConsumerForLogin)()


            'employeeData.Add({1, "sdfshfkhsdkhf", "kjhkdfsdf", "sdfjsdkfsf", "sdfjskjfksf"})
            employeeData.Add(New ConsumerForLogin() With {
                .MyId = 1,
                .Name = "Consumer Name",
                .Address = "Address ",
                .CustNo = "CustNo",
                .MobileNo = "MobileNo"
            })
            Return employeeData
```

and in the Xamarin to : 


```
var httpClient = new HttpClient();
            var response = await httpClient.GetStringAsync(AppSettings.ApiUrl + "Consumer/GetConsumerDetailsJSonInList?xCustNo=" + txtCustNo.Text);
         
            var login = JsonConvert.DeserializeObject<List<ConsumerInformation>>(response);
```

but its giving me an error in line : 


```
var response = await httpClient.GetStringAsync(AppSettings.ApiUrl + "Consumer/GetConsumerDetailsJSonInList?xCustNo=" + txtCustNo.Text);
```

the error i am getting is : 

```
System.InvalidCastException: 'Specified cast is not valid.'
```

puzzled as to why i am getting this error even after simplifying the code

----------


## jmcilhinney

Are you absolutely sure it's on that line? What does the stack trace say?

----------


## kuldevbhasin

i put a break point and after this line it gives me the error : 

Your app has entered a break state, but there is no code to show because all threads were executing external code (typically system or framework code).

----------


## kuldevbhasin

jmcilhinney u r right its not giving the error on that line. it is showing the data what i changed more is the sequence in the WebAPI 
i changed it from : 


```
employeeData.Add(New ConsumerForLogin() With {
                .MyId = 1,
                .Name = "Consumer Name",
                .Address = "Address ",
                .CustNo = "CustNo",
                .MobileNo = "MobileNo"
            })
```

to : 


```
  employeeData.Add(New ConsumerForLogin() With {
                .MyId = 1,
                .CustNo = "CustNo",
                .Name = "Consumer Name",
                .Address = "Address ",
                .MobileNo = "MobileNo"
            })
```

does the sequence too has to be the same ? 
it is showing the data in debug but giving the error at the end of the function

----------


## kuldevbhasin

hi. thankx a lot for the help. 
i got it working. 
1st i think the sequence should be same and secondly the problem was somewhere showing it in the listview
took the data in variables and its working fine.
thanks a lot for your guidance.

----------

