如何从可移植类库调用REST服务? [英] How to call REST services from Portable Class Library?

查看:75
本文介绍了如何从可移植类库调用REST服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标项目是Windows 8,WinRT和Windows Phone8.为了共享源,我正在使用可移植类库作为解决方案.我需要调用在另一个MVC Web Api项目中创建的一些REST服务,但是PCL中没有 HttpClient 类.哪一个是解决问题的好方法?我在考虑一个服务接口,然后为每个平台创建一个项目,分别使用 HttpClient WebClient 或相应的类.这种方法可能有效,但我想知道是否还有其他方法.

My target projects are Windows 8, WinRT and Windows Phone 8. I am using Portable Class Libraries for the solution in order to share the sources. I need to call some REST services created in another MVC Web Api project but HttpClient class is not available in the PCL. Which would be a good approach to solve it? I was thinking in a service interface and then to create a project for each platform, using HttpClient, WebClient or the appropriate class in each case. This approach could work but I was wondering if there are other ways.

推荐答案

HttpClient不一定是可移植的.唯一的其他方法是创建每个项目将实现的独立库,并按照您的描述进行操作.这样,您就可以在想要定位的所有平台上实现通用性.

HttpClient is not necessarily portable from Microsoft's view. The only other way is to create separate libraries that each project will implement, and do as you have described. This way, you can achieve commonality across all the platforms you desire to target.

我认为与您要定位的平台相对应.如果您必须有单独的项目,则可以将代码文件链接到另一个项目,因此不必维护多个项目.项目,甚至使用项目链接器(尽管我不会知道是否存在2012年版本.

I thought there was some level of equivalency when it came to the platforms you are targeting... If you have to have separate projects, you could link your code files to the other project so you don't have to maintain multiple projects, or even use Project Linker (though I don't know if a 2012 version exists).

这篇关于如何从可移植类库调用REST服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆