Reputation: 4173
I create a wcf using the following code :
[ServiceContract]
public interface IRestServiceImpl
{
[OperationContract]
[WebGet( ResponseFormat = WebMessageFormat.Json,
BodyStyle =WebMessageBodyStyle.Wrapped,
UriTemplate = "json")]
string JSONData();
}
public class RestServiceImpl : IRestServiceImpl
{
public string JSONData()
{
return "You Requested Prodcut";
}
}
and I added WCF to local IIS and it is working fine as the following:
when I am trying to get value from xamarin.forms app I get an exception
System.Net.WebExceptionStatus.ConnectFailure
, what the result should be ?
private async Task DownloadInfo()
{
var Uri = "http://localhost:8020/wcfrest/RestServiceImpl.svc/json";
var httpClient = new HttpClient();
var json= await httpClient.GetStringAsync(Uri);//I get exception here System.Net.WebExceptionStatus.ConnectFailure
}
Upvotes: 0
Views: 207
Reputation: 2105
It can be caused by quite a few things:
Did you add Internet permission to your app?
Are you sure that your device is in the same network as your API?
Try to use an IP address instead of localhost
Add host to your HttpClient object:
var httpClient = new HttpClient { Host = "localhost" };
Upvotes: 1