首页 > 解决方案 > 如何在 Xamrin Android 应用程序中使用 ASMX soap?

问题描述

我下载了示例,并在https://docs.microsoft.com/en-us/xamarin/xamarin-forms/data-cloud/web-的 Xamarin 表单中完成了“使用 ASP.NET Web 服务 (ASMX)”的教程服务/asmx。如果我从 Visual Studio 运行,Web 服务在浏览器中运行一切正常。如果我将 android 应用程序设为它运行的启动项目,但不会从服务中获取待办事项。我已经制定了防火墙规则,修改了使用 ASP.NET Web 服务 (ASMX),并在您的机器上创建了自签名开发证书。

我坚持的是如何配置您的项目以使用适当的 HttpClient 网络堆栈进行调试构建。有关详细信息,请参阅配置您的项目。

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

下面的代码去哪里了?我是否在下面的代码中将我的端口更改为 49178?

//设备类 public static string BaseAddress = Device.RuntimePlatform == Device.Android ? " https://10.0.2.2:5001 " : " https://localhost:5001 "; 公共静态字符串 TodoItemsUrl = $"{BaseAddress}/api/todoitems/";

标签: c#androidxamarinsoapandroid-webservice

解决方案


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

推荐阅读