none
WCF Rest Windows Phone RRS feed

  • Question

  • Hello,

    I am new. I wants to know how to call WCF Rest Service from Windows Phone 8.1 Runtime app.

    Tuesday, February 17, 2015 9:19 AM

Answers

  • Hi Hellotesttest,

    We can use the HttpClient class to help us cosume the WCF Rest Service from the Windows Phone 8.1 Runtime app.

    For example you have this ServiceContract in your WCF Rest Service:

       [ServiceContract]
        public interface IService1
        { 
            [OperationContract]
            [WebGet(UriTemplate = "Test")]
            string Test();
           }
    


    Then in Windows Phone you can use this code to consume the WCF Rest Service:

     private async void Test()
       {
           HttpClient MyHttpClient = new HttpClient();
           HttpRequestMessage MyRequest = new HttpRequestMessage(HttpMethod.Get, http://******/Service1.svc/Test);
           HttpResponseMessage MyResponse = await MyHttpClient.SendAsync(MyRequest);
           string MyData = await MyResponse.Content.ReadAsStringAsync();
           MessageDialo MyDialog = new MessageDialog(MyData);
           await MyDialog.ShowAsync();
          
       }
    

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, February 17, 2015 10:13 AM
    Owner