简体   繁体   English

使用Android Xamarin消费网络服务

[英]Consuming web service with android xamarin

I have built an app: click on the button then it gives out a sentence from HelloWorld(). 我已经构建了一个应用程序:单击按钮,然后从HelloWorld()中给出一句话。 I have put my web service on IIS and it works well. 我已将Web服务放在IIS上,并且运行良好。 I can access the web service on browsers and on my emulator also, when I change "localhost" to my IPv4 address. 当我将“ localhost”更改为我的IPv4地址时,可以在浏览器和仿真器上访问Web服务。 Everything is working fine. 一切正常。 But when I deploy the app, it gives back the Exceptions: ConnectionFailure (connection refused). 但是,当我部署该应用程序时,它会返回以下异常:ConnectionFailure(连接被拒绝)。 Do you know how to solve this problem? 你知道如何解决这个问题吗? I add my web service as web reference. 我将我的Web服务添加为Web参考。 I don't know why it still can't work. 我不知道为什么它仍然无法工作。 Have been stuck for this for 2 weeks. 已经被卡了两个星期了。 Please help me. 请帮我。 Thanks a lot. 非常感谢。

This my code connecting to the web service in Android app: 这是我的代码,连接到Android应用中的Web服务:

protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);            
            Button button = FindViewById<Button>(Resource.Id.MyButton);
            TextView txt = FindViewById<TextView>(Resource.Id.textView1);
            button.Click += delegate
            {
                WebReference.websv connect = new WebReference.websv();
                connect.Url = "http://192.168.xxx.xxx/tigonkhung.com/websv.asmx";
                txt.Text = connect.HelloWorld();

            };

        }

This is the web service in the emulator 这是模拟器中的Web服务

I used the tutorial on Xamarin's website when I was learning. 我在学习时就使用Xamarin网站上的教程。 Take a look at this tutorial here to see if it helps. 这里看一下本教程,看看是否有帮助。 I must mention that i was using WCF however. 我必须提到我正在使用WCF。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM