首页 > 解决方案 > 如何使用 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
            }
  
        }

并感谢所有答案

标签: c#androidweb-servicesxamarinasmx

解决方案


推荐阅读