0
votes

I have a xamarin form apps and I need it to consume an asmx web service. I encounter error when creating class in Android platform to implement the interface.

I have following this tutorial (https://www.c-sharpcorner.com/article/consuming-asmx-services-in-xamarin-forms/) to consume the asmx web service. I have this web method called "GetAllProjects" which will return List. I keep encounter error for the line of code: "return new List(result);" (refer to the codes below).

Error message: Error CS1503 Argument 1: cannot convert from 'IMSr2.Droid.IMSWS.Project[]' to 'int'. How should I return the result from the web service?

public async Task<List<IProject>> GetAllProjects(string criteria = null)
{
    return await Task.Run(() =>
    {
        var result = service.GetAllProjects();

        return new List<IProject>(result);
        /* How should I return the result from the web service?*/
    });
}

/* This hello world is working*/
public Task<string> HelloWorld()
{
    return Task.Run(() =>
    {
        return service.HelloWorld();
    });
}

I am expecting the same result as the tutorial: https://www.c-sharpcorner.com/article/consuming-asmx-services-in-xamarin-forms/ I need to return the result from the webservice call ("GetAllProjects") and display in the listview. Appreciate for help.

1
Can you post the web method called "GetAllProjects" . The return type is not consistent.Bruno Caceiro
<WebMethod()> _ Public Function GetAllProjects() As List(Of Project) Dim lstProject As New List(Of Project)() lstProject.Add(New Project("1", "Project 1")) lstProject.Add(New Project("2", "Project 2")) lstProject.Add(New Project("3", "Project 3")) Return lstProject End Functionuser3655427
This is what you meant? So sorry I am pretty new to Xamarin form and c# in general.user3655427
Edit your response and put the code there, for readability purposesBruno Caceiro

1 Answers

0
votes

If you check the error statement correctly it says IMSr2.Droid.IMSWS.Project[]' to 'int' which clearly means that the method of your Service object by the name of getallprojects returns int

i.e.

 service.GetAllProjects(); 

Is returning int when it should be returning Project[].

Check return type for GetAllProjects