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.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Carriage Return (ASCII chr 13) is missing from tex
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
Quite late, but here's a simple code I had to do, PLC is targeted for everything except XBox 360 ( might work too ). I could not use HttpClient for this target list.
Microsoft has rewritten the
HttpClient
library to be portable (PCL) and it's here on NuGet.For the time being, it's only available as pre-release so if you're using the NuGet GUI package manager make sure you set to "Include Prerelease".From the command line:Portable REST has recently become available on GitHub and should help making web requests given that WebClient is unavailable:
https://github.com/advancedrei/PortableRest#readme
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.
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).