使用WCF的Windows Phone 8.1应用程序
本文关键字:应用程序 Phone Windows WCF 使用 | 更新日期: 2023-09-27 18:25:59
我是Windows phone 8.1开发的新手。有人能向我推荐一些使用WCF服务的完整示例吗。我看到了一些例子,但我无法跟上并完成这些例子。请帮帮我。提前谢谢。
您可以从Windows Phone 8.1应用程序调用WCF服务的唯一方法是,如果您的WCF服务是RESTful的,那么您可以使用HTTP请求来调用它。
下面是一个调用WCF服务并返回字符串的基本函数:
private async void CallService()
{
// Create HttpClient
HttpClient httpClient = new System.Net.Http.HttpClient();
// Do the request (replace localhost:18362/xxx.svc/xxx by your own service url
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost:18362/Service1.svc/GetData");
// Get the response
HttpResponseMessage response = await httpClient.SendAsync(request);
// Read the response (here a string)
string data = await response.Content.ReadAsStringAsync();
}