Answered by:
RESTful solution for C++

Question
-
I was wondering what my options were for consuming REST web services in C++. I have a metro style DirectX application that would also like to communicate with the web.
I have tried to make a C# WinRT component that uses System.Net.Http.HttpClient. I'm able to load the component fine but if I make a call to a method that uses System.Net.Http.HttpClient I get access denied. I have the internet capability checked in my C++ application. Testing this component in a C# application with the internet capability enabled I am able to communicate just fine. What's more, adding the C++ project's Package.appxmanifest into the C# component project allows my C++ application to communicate with the web (no access denied) for exactly one build, if I build again I once again get access denied.
Any help would be appreciated, thanks!
Wednesday, October 5, 2011 4:12 AM
Answers
-
I responded this on the other thread about generic REST API in C++. For specific API for SkyDrive, the team is aware about the absence of a C++ API, and the right folks are thinking about it.
As of now there is no WinRT API for doing this. Even C# and JScript make use of functionality that comes with their respective frameworks (.NET Framework and WinJS respectively).
I agree that having a common WinRT API for all languages would be the best thing. But for now you may want to look at some existing C++ ways of doing this:
- http://cpp-netlib.github.com/ : This is proposed to be a part of Boost
- http://pocoproject.org/ : They have a good Http Client
Thanks
Raman- Proposed as answer by Raman Sharma Tuesday, November 1, 2011 11:39 PM
- Marked as answer by DavidLambMicrosoft employee, Moderator Monday, November 21, 2011 9:57 PM
Tuesday, November 1, 2011 8:24 PM
All replies
-
We have used ActiveMQ with C++ as well as C#. There is also MSMQ. Not sure what you need from the web. If its just information then you might consider some, if you are looking for straight HTTP communications try this article on how to use the wininet dll http://www.codeproject.com/KB/IP/simplehttpclient.aspx
there is also winhttp. Here is a MS link comparing the two.
http://msdn.microsoft.com/en-us/library/windows/desktop/hh227298(v=vs.85).aspx
bfxtech.comWednesday, October 5, 2011 2:52 PM -
We have used ActiveMQ with C++ as well as C#. There is also MSMQ. Not sure what you need from the web. If its just information then you might consider some, if you are looking for straight HTTP communications try this article on how to use the wininet dll http://www.codeproject.com/KB/IP/simplehttpclient.aspx
there is also winhttp. Here is a MS link comparing the two.
http://msdn.microsoft.com/en-us/library/windows/desktop/hh227298(v=vs.85).aspx
bfxtech.com
He's asking this from a WinRT perspective. Classic solutions may not be supported there.
http://blog.voidnish.comWednesday, October 5, 2011 4:31 PM -
Check out the background transfer APIs: http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.backgroundtransfer(v=VS.85).aspx. I've used them to retrieve data from RESTful services in the past.
- Proposed as answer by Larry Osterman [MSFT]Microsoft employee Wednesday, October 5, 2011 5:10 PM
Wednesday, October 5, 2011 5:09 PM -
Anyone know the technical reason why the "Access denied" error from the original poster's question?Friday, October 21, 2011 3:54 AM
-
Hi Larry, this doesn't really help. It seems to be a workaround for really (what should be) a simple RESTful http class. Will WinRT come out with such a class for C++? It doesn't make sense that both C# and JS have them but C++ doesn't.Tuesday, November 1, 2011 5:14 PM
-
And it seems that the REST API would come in handy for supporting Skydrive from C++.
There is also support for Skydrive in C# and JS but not in WinRT or C++.
There was a discussion of a C++ sample for Skydrive, but nothing is visible this month.
Tuesday, November 1, 2011 6:20 PM -
I responded this on the other thread about generic REST API in C++. For specific API for SkyDrive, the team is aware about the absence of a C++ API, and the right folks are thinking about it.
As of now there is no WinRT API for doing this. Even C# and JScript make use of functionality that comes with their respective frameworks (.NET Framework and WinJS respectively).
I agree that having a common WinRT API for all languages would be the best thing. But for now you may want to look at some existing C++ ways of doing this:
- http://cpp-netlib.github.com/ : This is proposed to be a part of Boost
- http://pocoproject.org/ : They have a good Http Client
Thanks
Raman- Proposed as answer by Raman Sharma Tuesday, November 1, 2011 11:39 PM
- Marked as answer by DavidLambMicrosoft employee, Moderator Monday, November 21, 2011 9:57 PM
Tuesday, November 1, 2011 8:24 PM -
@stugreco
See if the ChecknetIsolation tool helps identify a missing capability. If not, where do you see an access denied error bubble up? Are you using a C# WinRT Component (Class Library) from C++ as well?
//build/ demo of the tool:
Debugging connected Windows 8 apps
TOOL-588T
Speakers: Raghu Gatta
http://channel9.msdn.com/Events/BUILD/BUILD2011/TOOL-588T
(Starts) at 19:15 into the videoAn article walkthrough:
http://msdn.microsoft.com/en-us/library/windows/apps/hh452759
review the sectionsection starting with:
Network isolation and troubleshootingTuesday, November 1, 2011 11:37 PMModerator -
Hi Larry, I tried using the background transfer api. Created a temp file and called a background transfer on the rest api. Didnt work for me. Can you provide a code snippet ?Thursday, January 12, 2012 5:30 PM
-
i have been able to consume REST web services from Salesforce chatte using C++ in win 8 metro.
i have detailed that in my blog at
Tuesday, July 24, 2012 6:45 AM -
The C++ HTTP client sample is now at
http://code.msdn.microsoft.com/windowsapps/HttpClient-sample-55700664Tuesday, August 21, 2012 9:17 PM -
Will the above provided HTTP client work with Windows Phone Runtime Component also? When trying to use, it complains for InMemoryRandomAccessStream missing.
If not, is there a workaround for using the HTTP client work in WPRT. Please suggest.
Monday, May 6, 2013 2:14 PM -
I know this is an old thread, but for anyone still looking for options on how to interact with a REST service in C++ you should also take a look at the C++ REST SDK (Casablanca). It works with store applications, desktop, and on Linux.Thursday, May 16, 2013 11:06 PM
-
New in Windows 8.1: the Windows.Web.Http HttpClient API. This is an easy-to-use, full-featured HTTP API that works in all languages: C++, .NET (C#, VB) and JavaScript. Advantages of the new API include: strongly typed headers (meaning: you write fewer bugs in less time), full support for standard WinRT async concepts and data types.
HttpClient also lets you inject your modular filter code into the HTTP processing pipeline, letting you handle logging, testing, retry and auth more naturally. Samples of filters include retry and metered network filters in the HttpClient sample, and OAUTH and OAUTH 2.0 support in the Web Authentication Broker sample.
(Note that the existing IXHR2 code is still available for developers, and your existing Windows 8 code should continue to work as expected)
There's a //build/ 2013 video for the new API at http://channel9.msdn.com/Events/Build/2013/4-092
We also have samples at http://code.msdn.microsoft.com/windowsapps/HttpClient-sample-55700664
There's an OAUTH 0 filter sample at http://code.msdn.microsoft.com/windowsapps/Web-Authentication-d0485122
And there's documentation at http://msdn.microsoft.com/en-us/library/windows/apps/windows.web.http.aspx
Network Developer Experience Team (Microsoft)
Tuesday, July 16, 2013 9:30 PM