我必须在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>
尝试此代码时出现错误:
发生一个或多个错误。发送请求时发生错误 _错误:ConnectFailure(连接被拒绝)_连接被拒绝
我真的希望有人能帮助我,我真的不知道怎么了。
答案 0 :(得分:0)
只需确保清单文件中包含以下行?
<uses-permission android:name="android.permission.INTERNET" />