c# - 如何使用 Visual Studio 从 Xamarin 调用 Web 服务?
问题描述
我是新来的,很抱歉我的英语不好。我是第一次开发 Xamarin APP,我想调用 Web 服务。我没有从 Web 服务获得任何结果,但出现以下异常:
ex.InnerException = {System.Net.WebException: Error: ConnectFailure (Connection refused) ---> System.Net.Sockets.SocketException: Connection refused
在 System.Net.Sockets.SocketAsyncResult.CheckIfThrowDelayedException () [0x00014] 在 /Users/builder/jenkins/workspace/archive-...."
看了很多YouTube视频,上网很久了,一直没找到解决办法。
这是我的网络服务:
//web Service from ASMX project
public class WStest : System.Web.Services.WebService {
[WebMethod(MessageName = "Test", Description = "test")]
[System.Xml.Serialization.XmlInclude(typeof(Result))]
public Result test() {
Result result = new Result();
result.msg = "test successful";
result.flag = 1;
result.userNum = "usernummer";
return result;
}
}
这只是 Xamrain 代码的一部分
private void Butsend_Click(object sender, EventArgs e) {
WStest.WStest test = new WStest.WStest();
test.testCompleted += Test_testCompleted;
test.testAsync(); //call Web Service
//throw new NotImplementedException();
}
private void Test_testCompleted(object sender, WStest.testCompletedEventArgs e)
{
try
{
var a = e.Result.msg;
}
catch(Exception ex)
{
Console.WriteLine(ex.InnerException); //here I get the exception
}
}
并感谢所有答案
解决方案
推荐阅读
- objective-c - 分离由 CGWindowListCopyWindowInfo 返回的真实和虚拟窗口
- javascript - e.pageX 和 pageY 将工具提示放在一个奇怪的区域
- c++ - boost asio tcp socket 1.70 不向后兼容
- php - 无法从 php 执行的 shell 脚本正确挂载加密分区
- python - 在 pandas 中使用字典作为条件
- jmeter - 使用 UDP 的桌面应用程序的性能测试
- c++ - 来自不同翻译单元的 consteval 函数会干扰吗?
- javascript - 如何在不更改现有值的情况下使用相同的名称设置属性
- javascript - vue发送param值,声明发送哪个param
- java - Spring Security 使多个应用程序上的 http 会话无效?