c# - 如何在 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 网络堆栈进行调试构建。有关详细信息,请参阅配置您的项目。
下面的代码去哪里了?我是否在下面的代码中将我的端口更改为 49178?
//设备类 public static string BaseAddress = Device.RuntimePlatform == Device.Android ? " https://10.0.2.2:5001 " : " https://localhost:5001 "; 公共静态字符串 TodoItemsUrl = $"{BaseAddress}/api/todoitems/";
解决方案
//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!!!
推荐阅读
- python - 如何序列化 Python 对象的位置参数和非位置参数?
- php - 从内容中删除 []
- excel - 更改工作表 VBA Excel 中所有图表的字体大小
- haskell - 将 Maybe String 转换为 (Maybe?) Integer
- angular - Angular Pipe 在文本不完全可见时显示工具提示
- typescript - TypeScript 不遵循逻辑
- python - 在数据集中添加新的数字范围作为列
- java - HTML 表单参数全部为空
- amazon-s3 - Vertica S3 导出 - 导出文件中的列顺序
- sql - 从oracle中的一张表中获取关系数据