Xamarin.Forms不能得到WCF结果的方法,通过网址
问题描述:
我用下面的代码创建WCF:Xamarin.Forms不能得到WCF结果的方法,通过网址
[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";
}
}
当我试图从xamarin.forms应用程序,我得到一个异常值
System.Net.WebExceptionStatus.ConnectFailure
,结果应该是什么?
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
}
答
它可以通过颇有几件事情引起的:
你加上网权限,您的应用程序?
你确定你的设备是相同的网络API吗?
尝试使用IP地址而不是本地主机
-
主机添加到您的HttpClient对象:
VAR的HttpClient =新的HttpClient {主机= “localhost” 的};
感谢您的提示:) –
确实有帮助您吗? –