【问题标题】:Can't call a Web Service from Android but It work from UWP无法从 Android 调用 Web 服务,但它可以从 UWP 工作
【发布时间】:2019-11-06 23:54:36
【问题描述】:

我必须在 Xamarin 项目中实现 Web 服务。 所以我创建了一个简单的 Web 服务来做一些测试。有我以前用的代码:

using (HttpClient client = new HttpClient()) {
                client.BaseAddress = new Uri("http://localhost:62056/");
                client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                HttpResponseMessage response = client.GetAsync("DataTransferTest.svc/HelloWorld").Result;
                string json = response.Content.ReadAsStringAsync().Result;    
}

我已经尝试将http://localhost:62056/ 更改为http:10.0.0.2:62056,但没有任何改变。

我已经像这样配置我的 ISS express 了:

<site name="LogiStock.WebServices2" id="4">
                <application path="/" applicationPool="Clr4IntegratedAppPool">
                    <virtualDirectory path="/" physicalPath="D:\TeamExplorer\LogiStock-1.0.1\LogiStock.WebServices2" />
                </application>
                <bindings>
                    <binding protocol="http" bindingInformation="*:62056:localhost" />
                    <binding protocol="http" bindingInformation="*:62056:192.168.90.139" />
                    <binding protocol="http" bindingInformation="*:62056:127.0.0.1" />
                </bindings>
            </site>

我在尝试这段代码时遇到了错误:

发生了一个或多个错误。发送请求时出错 _错误:连接失败(连接被拒绝)_连接被拒绝

真的希望有人能帮帮我,我真的不知道哪里错了..

【问题讨论】:

标签: android web-services wcf xamarin


【解决方案1】:

只是为了确保清单文件中有以下行?

<uses-permission android:name="android.permission.INTERNET" /> 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-22
    • 2012-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-08
    • 1970-01-01
    相关资源
    最近更新 更多