【问题标题】:Xamarin.Forms HttpClient to RESTful webserviceXamarin.Forms HttpClient 到 RESTful Web 服务
【发布时间】:2014-10-23 13:51:55
【问题描述】:
【问题讨论】:
标签:
ios
rest
httpclient
xamarin.forms
【解决方案1】:
您只需要为 WCF 或 SOAP 生成一个代理。休息应该工作得很好。这就是我在 PCL 中使用 HttpClient 实现 GET 到 REST 服务的方式。
using (var client = new HttpClient())
{
var result = await client.GetStringAsync(url);
return JsonConvert.DeserializeObject<Movie>(result);
}
当然,其他动词需要更多的工作。
您可能需要在 app.config 中进行绑定重定向吗?查看这篇关于添加重定向的博文:http://motzcod.es/post/78863496592/portable-class-libraries-httpclient-so-happy。
这是一个例子:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="2.0.5.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>