【问题标题】:Xamarin.Forms HttpClient to RESTful webserviceXamarin.Forms HttpClient 到 RESTful Web 服务
【发布时间】:2014-10-23 13:51:55
【问题描述】:

我有一个通过 HttpClient 访问 Web 服务的 Xamarin.Forms PCL 应用程序。该应用程序在 Android 上运行,但在 iOS 上它根本不连接到网络服务。我需要为 iOS 和 REST 创建代理吗?

我已经阅读了http://developer.xamarin.com/guides/cross-platform/application_fundamentals/web_services/ 此处的信息,但坦率地说,这让我很困惑。我尝试按照规定创建代理,但没有成功。如果有必要,我会坚持下去。

我也尝试了 HttpWebRequest 方法,但也没有成功。

【问题讨论】:

    标签: 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-18
      • 2011-03-19
      • 2016-09-28
      • 1970-01-01
      • 2012-09-12
      • 2012-09-10
      • 2017-12-29
      • 1970-01-01
      相关资源
      最近更新 更多