如何在xamarin forms应用程序中连接ASMX Webservice
我正在使用ASMX webservice开发一个应用程序。我不知道如何连接它。我在这里提到。如何在xamarin forms应用程序中连接ASMX Webservice,asmx,Asmx,我正在使用ASMX webservice开发一个应用程序。我不知道如何连接它。我在这里提到。 但是我不清楚怎么做。。任何人都可以使用ASMX web服务提供简单的应用程序…我将分享我的代码,因为我还需要连接到我的ASMX.NET web服务,经过大量的研究和几天的尝试,终于成功了。我看到许多帖子解释了其他方法,但这是我发现的最简单的方法,也是第一个对我有用的方法 (我正在连接到在另一个Visual Studio中以调试模式运行的web服务) 我将分享我的代码,因为我还需要连接到我的asmx.NE
但是我不清楚怎么做。。任何人都可以使用ASMX web服务提供简单的应用程序…我将分享我的代码,因为我还需要连接到我的ASMX.NET web服务,经过大量的研究和几天的尝试,终于成功了。我看到许多帖子解释了其他方法,但这是我发现的最简单的方法,也是第一个对我有用的方法 (我正在连接到在另一个Visual Studio中以调试模式运行的web服务)
我将分享我的代码,因为我还需要连接到我的asmx.NETWeb服务,经过大量的研究和几天的尝试,终于成功地做到了。我看到许多帖子解释了其他方法,但这是我发现的最简单的方法,也是第一个对我有用的方法 (我正在连接到在另一个Visual Studio中以调试模式运行的web服务)
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/xml"));
httpClient.DefaultRequestHeaders.Add("SOAPAction", "http://tempuri.org/WSLogin");
string wUser = "user";
string wPassword = "password";
string soapstr = string.Format(@"<?xml version=""1.0"" encoding=""utf-8""?>
<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">
<soap:Body>
<WSLogin xmlns=""http://tempuri.org/"">
<wUser>{0}</wUser>
<wPassword>{1}</wPassword>
</WSLogin>
</soap:Body>
</soap:Envelope>", wUser, wPassword);
var response = httpClient.PostAsync("http://localhost:49411/Default.asmx", new StringContent(soapstr, Encoding.UTF8, "text/xml")).Result;
var content = response.Content.ReadAsStringAsync().Result;
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using Xamarin.Forms;