0

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
    port is usually after host ... so you have to change `5001` also you have to use emulator because obviosuly `10.0.2.2` nor `localhost` will not work on real device – Selvin Dec 12 '19 at 16:28
  • I am running project and it is sending it to emulator it just isn't hitting the webservice or throwing error! – Jonathan Conley Dec 12 '19 at 17:12
  • *it just isn't hitting the webservice or throwing error!* we don't know about it - it's not in the question ... also if you are getting some error it's worth to include them in the question – Selvin Dec 12 '19 at 17:16
  • I will simplify Android application runs in debug, ASMX Soap service runs in debug. But does not communicate between themselves. Like sample picture shows by showing todo items! – Jonathan Conley Dec 12 '19 at 17:22
  • I am trying to do something that should be so very simple to implement! Just have a simple ASMX web service that my android app calls and display its returning data in a excel type format. I have the UI/UX done but this part has become a technical hurdle when it shouldn't be! – Jonathan Conley Dec 12 '19 at 17:29
  • 1
    is your webserver setup to allow external connections? Have you verified that your Android device/emulator can connect to the server? Are you getting any exceptions or errors? This is most likely a networking/connectivity issue. – Jason Dec 12 '19 at 17:33
  • The sample for this is sample showing this Xamarin Forms consuming ASMX web service is 100% Microsoft code. I guess my curiosity question also is why if you provide a sample for learning that it doesn't just unzip and with limited setup and configuration just run! – Jonathan Conley Dec 12 '19 at 17:34
  • because Microsoft can't control your development environment. As I said before, this is most likely a networking issue – Jason Dec 12 '19 at 17:48
  • Jason, I believe your right. Does the service have to run standalone IIS express? It runs when U run it inside of VS but not when I don't have project in debug from a browser address. – Jonathan Conley Dec 12 '19 at 17:55
  • You can configure the VS web server to allow external connections – Jason Dec 12 '19 at 17:59

1 Answers1

0
        //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!!!