How to consume ASMX soap in Xamrin Android application?

492 Views Asked by At

I downloaded sample, went through tutoral for "Consume an ASP.NET Web Service (ASMX)" in Xamarin forms at https://learn.microsoft.com/en-us/xamarin/xamarin-forms/data-cloud/web-services/asmx. If I run from visual studio the web service runs in browser all good. If I make the android app the startup project it runs but does not get the todo items from service. I have made fire wall rule, modified the Consume an ASP.NET Web Service (ASMX), and creating a self-signed development certificate on your machine.

What I am stuck on is how to configure your project to use the appropriate HttpClient network stack for your debug build. For more information, see Configure your project.

https://learn.microsoft.com/en-us/xamarin/cross-platform/deploy-test/connect-to-local-web-services#configure-your-project

where does the following code go? And do i change my port to 49178 in code below?

//Device class public static string BaseAddress = Device.RuntimePlatform == Device.Android ? "https://10.0.2.2:5001" : "https://localhost:5001"; public static string TodoItemsUrl = $"{BaseAddress}/api/todoitems/";

1

There are 1 best solutions below

0
Jonathan Conley On
        //The solution I found was to ignore Microsoft's 
         // tutorial and publish web service to local IIS

                    //change constants.cs

            namespace TodoASMX
                {
                    public static class Constants
                    {
                        // URL of ASMX service
                        public static string SoapUrl
                        {
                            get
                            {
                                var defaultUrl = "http://192.168.254.25/TodoService.asmx";
                                //var defaultUrl = "http://localhost:49178/TodoService.asmx";

                                if (Device.RuntimePlatform == Device.Android)
                                {
                                    // defaultUrl = "http://10.0.2.2:49178/TodoService.asmx";
                                    defaultUrl = "http://192.168.254.25/TodoService.asmx";
                                }

                                //Also in references.cs

                                public TodoService()
                                {
                                    //  this.Url = "http://localhost:49178/TodoService.asmx";
                                    this.Url = "http://192.168.254.25/TodoService.asmx";


                                    // and also in properties window of web reference

                                    //Times like these I really despise Microsoft!!!