我试图从
Windows Phone 8应用程序连接REST Web服务.
它几个星期以来一直在工作,但在没有变化之后,我得到了这个一般错误:
System.Net.WebException: The remote server returned an error:
NotFound.
我试图通过在线REST客户端和服务测试它正常工作
我试图处理Exception并通过以下代码将其解析为webException:
var we = ex.InnerException as WebException;
if (we != null)
{
var resp = we.Response as HttpWebResponse;
response.StatusCode = resp.StatusCode;
我没有得到更多信息,最终回复代码是:“NotFound”
任何人都知道可能导致此错误的原因是什么?
已经在服务器上实现了可信证书.如果服务器建议服务器有一个DNS条目,那么这个条目应该是客户DNS或电话主机文件.我做了什么和工作了一段时间,但现在它不起作用,但我检查了没有改变的事情
这是获取请求的示例,它可以在Windwos商店应用上进行探测:
async Task<object> GetHttps(string uri, string parRequest, Type returnType, params string[] parameters)
{
try
{
string strRequest = ConstructRequest(parRequest, parameters);
string encodedRequest = HttpUtility.UrlEncode(strRequest);
string requestURL = BackEndURL + uri + encodedRequest;
HttpWebRequest request = HttpWebRequest.Create(new Uri(requestURL, UriKind.Absolute)) as HttpWebRequest;
request.Headers["applicationName"] = AppName;
request.Headers["applicationPassword"] = AppPassword;
if (AppVersion > 1)
request.Headers["applicationVersion"] = AppVersion.ToString();
request.Method = "GET";
request.CookieContainer = cookieContainer;
var factory = new TaskFactory();
var getResponseTask = factory.FromAsync<WebResponse>(request.BeginGetResponse, request.EndGetResponse, null);
HttpWebResponse response = await getResponseTask as HttpWebResponse;
// string s = response.GetResponseStream().ToString();
if (response.StatusCode == HttpStatusCode.OK)
{
XmlSerializer serializer = new XmlSerializer(returnType);
object obj = serializer.Deserialize(response.GetResponseStream());
return obj;
}
else
{
var Instance = Activator.CreateInstance(returnType);
(Instance as ResponseBase).NetworkError = true;
(Instance as ResponseBase).StatusCode = response.StatusCode;
return Instance;
}
}
catch (Exception ex)
{
return HandleException(ex, returnType);
}
}
我试图监视来自Emulator的连接,我发现连接中出现此错误:
**
Authentication failed because the remote party has closed the
transport stream.
**
最佳答案 您看到客户端在服务中实现了服务器端证书.您是否在手机上安装了该证书?这可能是NotFound错误的原因.在测试应用程序之前,您是否可以尝试导航到手机或模拟器Internet Explorer中的服务?如果您这样做,您可以看到该服务在模拟器/手机Internet Explorer中工作?也许在那时,Internet Explorer会询问您有关安装证书的信息,然后您可以打开您的应用程序,它可以正常工作.
还要记住,如果您在模拟器中测试它,每次关闭它时,状态都会丢失,因此您需要重复安装证书的操作.
希望这可以帮助.