问题
I am trying to call method created correctly using WCF, I start debugging the project for WCF and the result as the following:
on my xamarin.forms code i used HttpClient
Library as the following:
private async Task DownloadInfo()
{
var Uri = "http://localhost:10300/RestServiceImpl.svc/json";
var httpClient = new HttpClient();
var json= await httpClient.GetStringAsync(Uri);
}
when I am trying to get json
result from Xamarin.Forms I get the following:
what I should do?
回答1:
It seems like you are inspecting the task there, this doesnt give that much information. You can try this little more structured approach.
using (var httpClient = new HttpClient())
{
httpClient.BaseAddress = new Uri("http://localhost:10300");
var request = "/RestServiceImpl.svc/json";
var result = await httpClient.GetAsync(request);
if (!result.IsSuccessStatusCode)
throw new HttpRequestException($"{result.StatusCode} \n {result.Content.ReadAsStringAsync().Result} \n\n {httpClient.BaseAddress}{request}");
var json = await result.Content.ReadAsStringAsync();
Debug.WriteLine(json);
}
来源:https://stackoverflow.com/questions/41680217/how-to-use-wcf-service-in-xamarin-forms-portable-class-library