locked
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 exceptions

    an 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.

    Monday, April 14, 2014 7:28 AM
    Moderator
  • 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)

    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.

    Monday, April 14, 2014 7:28 AM
    Moderator
  • 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)

    Monday, April 14, 2014 6:55 PM