Answered by:
I can't connect to my web service using httpclient in windows store app 8.1

Question
-
i have this simple method to connect to my rest web service using WCF
private async void readString()
{
try
{
HttpClient h = new HttpClient();
String UrlWebService = @"http://localhost:24662/BoxOfficeREST.svc/films";
h.DefaultRequestHeaders.ExpectContinue = false;
var reponse = await h.GetAsync(UrlWebService);
t.Text = await reponse.Content.ReadAsStringAsync();
}
catch (Exception e)
{ MessageDialog m = new MessageDialog(e.Message +" "+ e.InnerException.Message + " " + e.StackTrace);
m.ShowAsync();
}
}
When I excute it in a simple windows forms application there is no problem but in a windows store app 8.1 I have this exceptionsan error occurred while sending the request.
Unable to connect to the remote server
PS: the internet(client) and internet(client & server) and the private network(client) capabilities are checked
Saturday, April 12, 2014 10:43 AM
Answers
-
Hi Mnaouar,
Before using WCF for Windows Store App, I would suggest you to go through this article, because the usage in Windows Store App is a bit different from using it in WinForm: Accessing WCF Services with a Windows Store Client App
"Unable to connect to the remote server" seems to be a endpoint is not supported issue.
--James
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.- Proposed as answer by Shreeharsh Ambli Monday, April 14, 2014 7:39 AM
- Marked as answer by Mnaouar Houssein Monday, April 14, 2014 2:16 PM
Monday, April 14, 2014 7:28 AMModerator -
I see two additional possible issues:
1. You are connecting to localhost -- that's a configuration that's specifically not supported with Windows Store apps (but see the information about enterprise support with sideloaded apps, and we will enable localhost temporarily while debugging)
2. You are setting the ExpectContinue flag; this tells me you're using the System.Net HttpClient. Have you considered the newer Windows.Web.Http.HttpClient? It's got the same basic programming model, but has a bunch of advantages. See the build talk here, and download the API poster here.
Network Developer Experience Team (Microsoft)
- Proposed as answer by Jamles HezModerator Tuesday, April 15, 2014 1:03 AM
- Marked as answer by Jamles HezModerator Tuesday, April 22, 2014 8:21 AM
Monday, April 14, 2014 6:55 PM
All replies
-
Hi Mnaouar,
Before using WCF for Windows Store App, I would suggest you to go through this article, because the usage in Windows Store App is a bit different from using it in WinForm: Accessing WCF Services with a Windows Store Client App
"Unable to connect to the remote server" seems to be a endpoint is not supported issue.
--James
<THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
Thanks
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.- Proposed as answer by Shreeharsh Ambli Monday, April 14, 2014 7:39 AM
- Marked as answer by Mnaouar Houssein Monday, April 14, 2014 2:16 PM
Monday, April 14, 2014 7:28 AMModerator -
Hi Jamles
It was a problem with my computer and i fixed it
Thank you :)
Monday, April 14, 2014 2:18 PM -
I see two additional possible issues:
1. You are connecting to localhost -- that's a configuration that's specifically not supported with Windows Store apps (but see the information about enterprise support with sideloaded apps, and we will enable localhost temporarily while debugging)
2. You are setting the ExpectContinue flag; this tells me you're using the System.Net HttpClient. Have you considered the newer Windows.Web.Http.HttpClient? It's got the same basic programming model, but has a bunch of advantages. See the build talk here, and download the API poster here.
Network Developer Experience Team (Microsoft)
- Proposed as answer by Jamles HezModerator Tuesday, April 15, 2014 1:03 AM
- Marked as answer by Jamles HezModerator Tuesday, April 22, 2014 8:21 AM
Monday, April 14, 2014 6:55 PM